标签:style blog http color os io for art
搞到凌晨4点一个没出,要gg了。
A. Golden System http://codeforces.com/contest/458/problem/A
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 const double q=(sqrt(5.0)+1)/2; 7 const int M=100010; 8 char a[M],b[M]; 9 int sa[M],sb[M]; 10 void gxrev(char c[]){ 11 for(int i=0,j=strlen(c)-1;i<j;i++,j--){ 12 swap(c[i],c[j]); 13 } 14 } 15 double gxpow(double x,int p){ 16 double res=1; 17 while(p){ 18 if(p&1) res*=x; 19 x*=x; 20 p>>=1; 21 } 22 return res; 23 } 24 int main(){ 25 while(~scanf("%s%s",a,b)){ 26 gxrev(a); 27 gxrev(b); 28 int la=strlen(a); 29 int lb=strlen(b); 30 int len=max(la,lb); 31 for(int i=la;i<len;i++) a[i]=‘0‘; 32 for(int i=lb;i<len;i++) b[i]=‘0‘; 33 a[len]=b[len]=0; 34 for(int i=0;i<len;i++){ 35 sa[i]=a[i]-‘0‘; 36 sb[i]=b[i]-‘0‘; 37 } 38 for(int i=0;i<len;i++){ 39 if(i+2<len){ 40 if(sa[i]&&sa[i+1]){ 41 int sma=min(sa[i],sa[i+1]); 42 sa[i]-=sma; 43 sa[i+1]-=sma; 44 sa[i+2]+=sma; 45 } 46 if(sb[i]&&sb[i+1]){ 47 int sma=min(sb[i],sb[i+1]); 48 sb[i]-=sma; 49 sb[i+1]-=sma; 50 sb[i+2]+=sma; 51 } 52 } 53 } 54 int flag=0; 55 for(int i=len-1;i>=0;i--){ 56 int sma=min(sa[i],sb[i]); 57 sa[i]-=sma; 58 sb[i]-=sma; 59 if(i-2>=0){ 60 if(sa[i]){ 61 if(sa[i]>M){ 62 flag=1; 63 break; 64 } 65 sa[i-1]+=sa[i]; 66 sa[i-2]+=sa[i]; 67 sa[i]=0; 68 } 69 if(sb[i]){ 70 if(sb[i]>M){ 71 flag=-1; 72 break; 73 } 74 sb[i-1]+=sb[i]; 75 sb[i-2]+=sb[i]; 76 sb[i]=0; 77 } 78 } 79 } 80 if(flag==1){ 81 puts(">"); 82 continue; 83 } 84 if(flag==-1){ 85 puts("<"); 86 continue; 87 } 88 double suma=0,sumb=0; 89 for(int i=0;i<len&&i<3;i++){ 90 suma+=gxpow(q,i)*sa[i]; 91 sumb+=gxpow(q,i)*sb[i]; 92 } 93 if(suma>sumb) puts(">"); 94 else if(suma<sumb) puts("<"); 95 else puts("="); 96 } 97 return 0; 98 }
end
MemSQL Start[c]UP 2.0 - Round 2 - Online Round,布布扣,bubuko.com
MemSQL Start[c]UP 2.0 - Round 2 - Online Round
标签:style blog http color os io for art
原文地址:http://www.cnblogs.com/gaolzzxin/p/3904183.html