解题思路: 贪心的选择使得获胜方人数与另外两方人数和的差最大,因此优先选择差最大的事件
注意事项: 获胜仅有三种情况,要么x要么y要么z
参考代码:
n = int(input()) x = list(map(int,input().split())) y = list(map(int,input().split())) z = list(map(int,input().split())) win_x = sorted([x[i]-(y[i]+z[i]) for i in range(n)],reverse = True) win_y = sorted([y[i]-(x[i]+z[i]) for i in range(n)],reverse = True) win_z = sorted([z[i]-(x[i]+y[i]) for i in range(n)],reverse = True) sum_x,sum_y,sum_z = 0, 0, 0 num_x,num_y,num_z = 0, 0, 0 ans = 0 for i in range(n): sum_x += win_x[i] sum_y += win_y[i] sum_z += win_z[i] num_x = num_y = num_z = i+1 if sum_x > 0: ans = max(ans,num_x) if sum_y > 0: ans = max(ans,num_y) if sum_z > 0: ans = max(ans,num_z) if sum_x<=0 and sum_y<=0 and sum_z<=0: break print(ans if ans else -1)
0.0分
6 人评分
【排队买票】 (C语言代码)浏览:1476 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:720 |
A+B for Input-Output Practice (III) (C语言代码)浏览:652 |
去掉双斜杠注释 (C语言代码)浏览:1963 |
校门外的树 (C语言代码)浏览:1166 |
K-进制数 (C++代码)浏览:938 |
C语言训练-立方和不等式 (C语言代码)浏览:779 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:790 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:1215 |
Minesweeper (C语言描述,蓝桥杯)浏览:1176 |