标签:
11.8
闲来无事补CF。
CF 592 C The Big Race
题目比较简单。点在于有一个大数比较可以用log弄掉。
算LCM要先除再乘。算log要先强转double。
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cmath> 5 using namespace std; 6 typedef long long LL; 7 8 LL gcd(LL a,LL b) 9 { 10 return b?gcd(b,a%b):a; 11 } 12 13 int main(void) 14 { 15 LL t,w,b; 16 scanf("%I64d%I64d%I64d",&t,&w,&b); 17 LL x,GCD=gcd(w,b),LCM=b/GCD*w; 18 if(log(double(w))+log(double(b))>log(double(t))+log(double(GCD))) x=min(min(w-1,b-1),t); 19 else x=t/LCM*min(w,b)+min(t%LCM,min(w-1,b-1)); 20 GCD=gcd(x,t); 21 printf("%I64d/%I64d\n",x/GCD,t/GCD); 22 return 0; 23 }
标签:
原文地址:http://www.cnblogs.com/Aguin/p/4948112.html