2011年4月5日

poj 2115

摘要: 扩展欧几里得。代码:#include<iostream>#include<fstream>using namespace std;long long n,x,y;long long gcd(long long s,long long t){ if(t==0) { x=1;y=0; return s; } long long i=gcd(t,s%t); long long tmp=x; x=y; y=tmp-s/t*y; return i;}void read(){// ifstream cin("in.txt"); int i,j,k; long l 阅读全文

posted @ 2011-04-05 21:50 宇宙吾心 阅读(387) 评论(0) 推荐(0)

poj 2891

摘要: 中国剩余定理。代码:#include<iostream>#include<fstream>using namespace std;long long x,y,t;long long egcd(long long a, long long b){ if (b == 0) { x = 1; y = 0; return a; } else { long long e = egcd(b, a % b); t = x; x = y; y = t - a / b * y; return e; }}void read(){// ifstream cin("in.txt&qu 阅读全文

posted @ 2011-04-05 20:44 宇宙吾心 阅读(865) 评论(0) 推荐(0)

poj 1006

摘要: 中国剩余定理。代码:#include<iostream>#include<fstream>using namespace std;void read(){// ifstream cin("in.txt"); int i,j,k,s,t,n=0; while(cin>>j>>k>>s>>t){ if(j==-1&&k==-1&&s==-1&&t==-1) return; n++; i=(5544*j+14421*k+1288*s-t)%21252; whil 阅读全文

posted @ 2011-04-05 20:09 宇宙吾心 阅读(146) 评论(0) 推荐(0)

poj 2282

摘要: 按位统计,,,先算各位,,个位是2的情况有413种,,,因为各位左边可以0~412,,,而右边没有数字,,,然后是十位,,,十位是2的有41*10 + 1*4种,,当左边从0~40时,,,右边可以从0~9,,,而左边为41时,,右边只能从0~3然后是百位,,,,百位有4*100种,,,,即左边从0~3,,右边从0~99千位有 1*1000,,,左边没有数字,,,右边0~999,,,,上面是计算1~9,,,,计算0的时候比较特殊,,,,原因是除了0这一个数字之外,,,,0不能做开头,,,可以看到在求1~9的个数的时候,,,都是分为2部分相乘,,,这样0的处理也很简单,,只需把相乘的左半部分-1, 阅读全文

posted @ 2011-04-05 13:09 宇宙吾心 阅读(605) 评论(0) 推荐(0)

poj poj 3286

摘要: 2282的简单版。代码:#include<iostream>#include<fstream>using namespace std;void solve(long long s,long long &ans){ int i,j,k; if(s<0) return; long long rgt=0,id=1; ans+=1; while(s>0){ int now=s%10; s/=10; for(i=0;i<1;i++) { if(now>i) { ans+=s*id; } else if(now==i) { if(s) ans+=(s 阅读全文

posted @ 2011-04-05 13:07 宇宙吾心 阅读(325) 评论(0) 推荐(0)

导航