上一页 1 ··· 23 24 25 26 27 28 29 30 31 ··· 36 下一页

2011年4月6日

poj 2142

摘要: 欧几里得。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;long long x,y;long long egcd(long long s,long long t){ if(t==0) { x=1; y=0; return s; } long long i=egcd(t,s%t); long long temp=x; x=y; y=temp-s/t*y; return i;}long long abs(long long s){ if(s<0) retur 阅读全文

posted @ 2011-04-06 15:49 宇宙吾心 阅读(571) 评论(0) 推荐(0)

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)

2011年4月4日

poj 1730

摘要: 注意精度。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;void read(){// ifstream cin("in.txt"); long long i,j,k,s; long long n; while(cin>>n){ if(n==0) return; k=0; if(n<0) { n=-n;k=1; } for(i=32;i>=1;i--){ j=ceil(pow(1.*n,1./i)); s=floor( 阅读全文

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

poj 1715

摘要: 注意题意,最多8位,可以不是8位。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;long long n;long long a[17][17];long long m[10];long long b[10];char c[20];int v[20];long long fun(int s){ if(s==0) return 1; else return s*fun(s-1);}void read(){ int i,j,k,s; cin>>n; if 阅读全文

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

2011年4月3日

poj 2480

摘要: 有意思的欧拉。注意精度。代码:#include<iostream>#include<fstream>using namespace std;int a[50001];long long n;void read(){// ifstream cin("in.txt"); long long i,j,k; for(i=4;i<=50000;i+=2) a[i]=1; for(i=3;i<=50000;i+=2) if(a[i]==0) for(j=2*i;j<=50000;j+=i) a[j]=1; while(cin>>n) 阅读全文

posted @ 2011-04-03 15:35 宇宙吾心 阅读(209) 评论(0) 推荐(0)

poj 3244

摘要: discuss中://数学好题//定义两个三元组I(xi,yi,zi)和J(xj,yj,zj),(可以看做是空间中的点)//他们的距离为D(I,J)=max{xi-xj,yi-yj,zi-zj}-min{xi-xj,yi-yj,zi-zj},//给定n个三元组(n<=200000),求任意两个三元组的差的和//抽化出来的模型是 max(a,b,c)-min(a,b,c),这个东西吧他放在数轴上 a,b,c//我们要求最大和最小的差就是这三个点构成的线段的距离,那么我们这里再变通下 是不是端点到中间那个点的距离//其实画出这个图的时候,就可以看到这个距离为(|a-b|+|b-c|+|c-a 阅读全文

posted @ 2011-04-03 14:32 宇宙吾心 阅读(252) 评论(0) 推荐(0)

上一页 1 ··· 23 24 25 26 27 28 29 30 31 ··· 36 下一页

导航