训练赛后补题 11
2020-07-03 个人训练赛后补题
题号B,原题CodeForces - 1153A 题目:

当时WA的代码:
1 #pragma warning (disable:4996) 2 #include <iostream> 3 #include<algorithm> 4 #include<stdio.h> 5 #include<math.h> 6 #include<string.h> 7 #include<string> 8 #define MAX1 100005 /*1e5 + 5*/ 9 #define MAX2 1000000005 /*le9 + 5*/ 10 #define MAX3 200005 /*2e5 + 5*/ 11 #define MAX4 5005 /*5e4 + 5*/ 12 #define MAX5 105 /*1e2 + 5*/ 13 #define T2 27 14 #define T3 18 15 using namespace std; 16 typedef long long int ll; 17 #define MOL 998244353 18 19 int main() { 20 int n, t, a[MAX5][2] = { 0 }, ans; 21 while (scanf("%d %d", &n, &t) != EOF) { 22 int i, j, needt = 100; 23 ans = 0; 24 int min = 240; 25 for (i = 0; i < n; ++i) { 26 scanf("%d %d", &a[i][0], &a[i][1]); 27 for (j = 0; (a[i][0] + j * a[i][1]) < t; j++); 28 needt = (a[i][0] + (--j) * a[i][1]) - t; 29 if (min > needt) { 30 min = needt; 31 ans = i + 1; 32 } 33 //cout << "\t" << i + 1 << ":min" << min << ":needt" << needt << endl; 34 } 35 printf("%d\n", ans); 36 } 37 return 0; 38 }
//----------补题------------
错因:审错题
修正代码【AC】:
1 #pragma warning (disable:4996) 2 #include <iostream> 3 #include<algorithm> 4 #include<stdio.h> 5 #include<math.h> 6 #include<string.h> 7 #include<string> 8 #define MAX1 100005 /*1e5 + 5*/ 9 #define MAX2 1000000005 /*le9 + 5*/ 10 #define MAX3 200005 /*2e5 + 5*/ 11 #define MAX4 5005 /*5e4 + 5*/ 12 #define MAX5 105 /*1e2 + 5*/ 13 #define T2 27 14 #define T3 18 15 using namespace std; 16 typedef long long int ll; 17 #define MOL 998244353 18 19 int main() { 20 int n, t, a, b, ans; 21 int i, j, k; 22 while (scanf("%d %d", &n, &t) != EOF) { 23 int min = MAX2; 24 for (i = 1; i <= n; ++i) { 25 scanf("%d %d", &a, &b); 26 int wait = 0; 27 if (a >= t)wait = a - t; 28 else { 29 if ((t - a) % b)j = (t - a) / b + 1; 30 else j = (t - a) / b; 31 wait = a + b * j - t; 32 } 33 if (min > wait) { 34 min = wait; 35 ans = i; 36 } 37 } 38 cout << ans << endl; 39 } 40 return 0; 41 }
//------------------7.27更新
暂时不补,刷题去啦

浙公网安备 33010602011771号