数学和计算机IQ题,贪心过。从计算机最低IQ的同学开始试探,是否可以调,直到最后一个。 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); double sumS = 0; for (int i = 0; i < n; i ++) { sumS += sc.nextInt(); } double sss = sumS / n; int m = sc.nextInt(); List<Integer> nums = new ArrayList<>(); double sumJ = 0; for (int i = 0; i < m; i ++) { int tmp = sc.nextInt(); nums.add(tmp); sumJ += tmp; } Collections.sort(nums); int cntJ = m; int cntS = n; int res = 0; for (int i = 0; i < m; i ++) { int num = nums.get(i); if ((sumS + num) / (cntS + 1) > sumS/cntS && (sumJ - num) / (cntJ - 1) > sumJ/cntJ) { sumS += num; sumJ -= num; cntS += 1; cntJ -= 1; res += 1; } } System.out.println(res); } sc.close(); } }
点赞 4

相关推荐

03-31 18:02
门头沟学院 Java
白日梦想家_等打包版:不要的哦佛给我
点赞 评论 收藏
分享
03-30 19:30
石家庄学院 Java
野蛮的柯基在游泳:都能入股了,还得是Java
点赞 评论 收藏
分享
牛客网
牛客企业服务