题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=551
呵呵,题目读的没错,可惜理解错了..==
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #include <algorithm> 5 #define LL long long 6 using namespace std; 7 int n, t1, t2; 8 int gcd(int a, int b) { 9 return b == 0 ? a : (gcd(b, a%b)); 10 } 11 int exg(int a, int b) { 12 return a/gcd(a,b)*b; 13 } 14 int main(void) { 15 //freopen("in.txt", "r", stdin); 16 while (~scanf("%d%d%d", &n, &t1, &t2)) { 17 int k = exg(t1, t2), s = k/t1 + k/t2, One = n/s, r = n%s, base = One*k, 18 Min = 0, cnt = 0, i, j; 19 if (t1>t2) swap(t1,t2); 20 //printf("s = %d r = %d\n", s, r); 21 if (r) 22 for (i = 1, j = 1; i+j <= s;) { 23 if (cnt >= r) break; 24 if (i * t1 < j * t2) Min=i*t1, i++, cnt++; 25 else if(i*t1 > j*t2) Min=j*t2, j++, cnt++; 26 else Min=j*t2, j++, i++, cnt+=2; 27 if (cnt >= r) break; 28 } 29 if ( (i-1)*t1!=(j-1)*t2 && Min == (i-1) * t1) cnt++, Min = max(Min, j*t2); 30 else if ( (i-1)*t1!=(j-1)*t2 && Min == (j-1) * t2) cnt++, Min = max(Min, i*t1); 31 //printf("cnt = %d\n", cnt); 32 printf("%d %d\n", cnt+s*One, base+Min); 33 } 34 return 0 ; 35 }
这场比赛就栽在了这道题目上面,从开场到结束前5分钟...