sgu551 Preparing Problem
July 18, 2013
Sgu
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=551 呵呵,题目读的没错,可惜理解错了..==
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
int n, t1, t2;
int gcd(int a, int b) {
return b == 0 ? a : (gcd(b, a%b));
}
int exg(int a, int b) {
return a/gcd(a,b)*b;
}
int main(void) {
//freopen("in.txt", "r", stdin);
while (~scanf("%d%d%d", &n, &t1, &t2)) {
int k = exg(t1, t2), s = k/t1 + k/t2, One = n/s, r = n%s, base = One*k,
Min = 0, cnt = 0, i, j;
if (t1>t2) swap(t1,t2);
//printf("s = %d r = %d\n", s, r);
if (r)
for (i = 1, j = 1; i+j <= s;) {
if (cnt >= r) break;
if (i * t1 < j * t2) Min=i*t1, i++, cnt++;
else if(i*t1 > j*t2) Min=j*t2, j++, cnt++;
else Min=j*t2, j++, i++, cnt+=2;
if (cnt >= r) break;
}
if ( (i-1)*t1!=(j-1)*t2 && Min == (i-1) * t1) cnt++, Min = max(Min, j*t2);
else if ( (i-1)*t1!=(j-1)*t2 && Min == (j-1) * t2) cnt++, Min = max(Min, i*t1);
//printf("cnt = %d\n", cnt);
printf("%d %d\n", cnt+s*One, base+Min);
}
return 0 ;
}
这场比赛就栽在了这道题目上面,从开场到结束前5分钟...