FOJ 2013 11 月赛 G
Problem 2138 久违的月赛之一
Accept: 55 Submit: 114 Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
好久没举月赛了,这次lqw给大家出了5道题,因为hsy学长宣传的很到位,吸引了n个DDMM们来做,另一位kk学长说,全做对的要给金奖,做对4题要给银奖,做对3题要给铜奖。统计数据的时候,发现每题分别在n个人中有n1、n2、n3、n4、n5个人通过,lqw灵机一动,问kk:“你猜,这次至少会有多少个人获奖?”由于题目太简单了,每题的通过人数一定大于等于最低获奖人数。
Input
第一行一个数字t,表示有多少组数据,每组数据如下所示(1000 < t < 5000, 100<=n<=1000000, n1,...,n5<=n):
n
n1 n2 n3 n4 n5
Output
针对每组数据,输出一个数,表示最低获奖人数。
Sample Input
2
4770 3844 3748 3296 3390 4759
5000 1944 2353 4589 2386 3837
Sample Output
3166
1703
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 int a[11]; 6 int find(int x, int n){ 7 int l = 0, r = n, m; 8 while (l < r){ 9 m = (l + r) >> 1; 10 if (x - 5 * m <= 2 * (n - m))r = m; 11 else l = m + 1; 12 } 13 return l; 14 } 15 int main(){ 16 int t,s,n,x; 17 scanf("%d", &t); 18 while (t--){ 19 scanf("%d", &n); 20 int x = 0; 21 for (int i = 0; i < 5; i++){scanf("%d", &a[i]); x += a[i];} 22 printf("%d\n", find(x,n)); 23 } 24 return 0; 25 }
浙公网安备 33010602011771号