上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 57 下一页

2011年7月22日

poj 3169 Layout

摘要: #include <iostream> //差分约束系统,Bellman-Ford算法using namespace std;const int inf=99999999;typedef struct Edge{ int u, v; // 起点,重点 int weight; // 边的权值}Edge;Edge edge[20020]; // 保存边的值int dist[1005]; // 结点到源点最小距离int nodenum, e,edgenum; // 结点数,边数,源点// 初始化图void init(){ // 输入结点数,边数 源点为V1 int ml,md; cin& 阅读全文

posted @ 2011-07-22 19:55 sysu_mjc 阅读(105) 评论(0) 推荐(0) 编辑

poj 3318 Matrix Multiplication

摘要: #include <iostream> //随机化算法using namespace std;int ma[505][505],mb[505][505],mc[505][505],n;int main(){ scanf("%d",&n); for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) scanf("%d",&ma[i][j]); //cin 会TLE for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) scanf(" 阅读全文

posted @ 2011-07-22 19:55 sysu_mjc 阅读(142) 评论(0) 推荐(0) 编辑

poj 3051 Satellite Photographs

摘要: #include<iostream> //bfs#include<deque>#include<string>using namespace std;int w,h,m,s,visited[1005][85];char str[1005][85];deque<int> col;void bfs(int i,int j){ while(!col.empty()) { int i=col.front()/10000,j=col.front()%10000; col.pop_front(); s++; if(i-1>=0&&str 阅读全文

posted @ 2011-07-22 19:54 sysu_mjc 阅读(119) 评论(0) 推荐(0) 编辑

poj 3077 Rounders

摘要: #include <iostream>#include <string>using namespace std;int main(){ int n;string str; cin>>n; while(n--) { cin>>str; if(str.size()==1) { cout<<str<<endl;continue; } int tag=0; for(int i=str.size()-1;i>=1;--i) { if(str[i]>'4'||(tag==1&&str[i]= 阅读全文

posted @ 2011-07-22 19:54 sysu_mjc 阅读(90) 评论(0) 推荐(0) 编辑

poj 3009 Curling 2.0

摘要: #include <iostream> //dfs#include <deque>using namespace std;int w,h,square[100][100],c,num;void dfs(int x,int y){ if(c>num) return; int i,j; //不能设为全局变量 if(y>1&&square[x][y-1]!=1) //向左 { for(j=y;j>=1&&square[x][j]==0;--j); if(j>=1&&square[x][j]==3) { n 阅读全文

posted @ 2011-07-22 19:53 sysu_mjc 阅读(119) 评论(0) 推荐(0) 编辑

poj 2983 Is the Information Reliable?

摘要: #include <iostream> //差分约束系统,Bellman-Ford算法using namespace std;typedef struct Edge{ int u, v; // 起点,重点 int weight; // 边的权值}Edge;Edge edge[300000]; // 保存边的值int dist[1010]; // 结点到源点最小距离int nodenum, e,edgenum; // 结点数,边数,源点// 初始化图void init(){ // 输入结点数,边数 引入附加源点V0 for(int i=1; i<=nodenum; ++i) d 阅读全文

posted @ 2011-07-22 19:52 sysu_mjc 阅读(96) 评论(0) 推荐(0) 编辑

poj 2924 Gauß in Elementary School

摘要: #include <iostream>#include <string>using namespace std;int compare(string str1, string str2){ while(!str1.empty()&&str1[0]=='0') { str1.erase(0,1); } while(!str2.empty()&&str2[0]=='0') { str2.erase(0,1); } if(str1.size() > str2.size()) //长度长的整数大于长度小的整数 阅读全文

posted @ 2011-07-22 19:52 sysu_mjc 阅读(218) 评论(2) 推荐(0) 编辑

poj 2773 Happy 2006

摘要: #include <iostream> //求出<=m的互质的 大于m的都是在上面加m的倍数 using namespace std;int prime[1000000];int gcd(int n,int m) { if(n<m) swap(n,m); int r; while(m!=0) { r=n%m; n=m; m=r; } return n;}int main(){ int m,k,i,j; while(cin>>m>>k) { j=0; for(i=1;i<=m;++i) //不能写成i<m,因为要考虑m==1的情况 if 阅读全文

posted @ 2011-07-22 19:51 sysu_mjc 阅读(139) 评论(0) 推荐(0) 编辑

poj 2891 Strange Way to Express Integers

摘要: /*对于线性同余方程组不满足( m1,m2,...,mk 两两互素)条件的情况:s ≡ r1 ( mod a1 ) ≡ r2 ( mod a2 ),其中不满足 a1,a2,...,ak 两两互素 可以看作 s=a1*x+r1=a2*y+r2, 即 a1*x-a2*y=r2-r1方程 a1 * x - a2 * y = r2-r1 有整数解的充要条件是 (r2-r1)%(a1,a2)==0求出 x 的最小非负整数解. 令 r1'= s=a1*x+r1=a2*y+r2 , a1'= lcm(a1,a2)则可以将两个方程合并成一个方程: s ≡ r1' ( mod a1 阅读全文

posted @ 2011-07-22 19:51 sysu_mjc 阅读(128) 评论(0) 推荐(0) 编辑

poj 2537 Tight words

摘要: #include <iostream> //DP#include<cmath>using namespace std;int main(){ int k,n; double dp[15][105]; //dp[i][j]表示最后一位数字为i,长度为j的可能组合数 while(cin>>k>>n) { memset(dp,0,sizeof(dp)); for(int i=1;i<=k+1;++i) dp[i][1]=1; for(int j=2;j<=n;++j) //长度为j for(int i=1;i<=k+1;++i) // 阅读全文

posted @ 2011-07-22 19:49 sysu_mjc 阅读(141) 评论(0) 推荐(0) 编辑

上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 57 下一页

导航