2011年7月17日

poj 1321 棋盘问题

摘要: #include<iostream>using namespace std;int board[10][10];int n,k,c;void dfs(int num)//深度搜索。棋盘上的一个点共有三种状态:未放棋子的棋盘点,放了棋子的棋盘点,空白点。分别用:等于0,大于0,小于0{ if(num>k) { c++; return; } for(int u=num-1;u<n;u++) { if(k-num>n-1-u) return; for(int i=0;i<n;i++) { //同一行不允许存在两个棋子 if(board[u][i]>0) br 阅读全文

posted @ 2011-07-17 23:59 sysu_mjc 阅读(127) 评论(0) 推荐(0) 编辑

poj 1323 Game Prediction

摘要: #include<iostream>#include<algorithm>#include<list>using namespace std;bool cmp(const int a,const int b){ return a>b;}int main(){ int n,m,i,count,ff=0;int cards[51]; while (cin>>m>>n&&n&&m) { for(i=1;i<=n;i++) cin>>cards[i]; sort(cards+1,card 阅读全文

posted @ 2011-07-17 23:59 sysu_mjc 阅读(127) 评论(0) 推荐(0) 编辑

poj 1298 The Hardest Problem Ever

摘要: #include<iostream>#include<string>using namespace std;int main(){ string start,str,end; while(cin>>start&&start!="ENDOFINPUT") { scanf("\n"); getline(cin,str); for(int i=0;i<str.size();i++) { if(str[i]>='A'&&str[i]<='E') 阅读全文

posted @ 2011-07-17 23:58 sysu_mjc 阅读(99) 评论(0) 推荐(0) 编辑

poj 1258 Agri-Net

摘要: #include<iostream> //最小生成树prim算法using namespace std;const int MAXN=105; //最大顶点数int n,edge[MAXN][MAXN]; //n记录顶点数struct MST //最小生成树的边{ int s,t,w;}mst[MAXN];void Prim(){ int sum=0,i,j,k; //sum记录最小生成树的路径和 for(i=0;i<n-1;i++) //顶点下标从0开始,默认选择顶点0加入生成树 { mst[i... 阅读全文

posted @ 2011-07-17 23:57 sysu_mjc 阅读(134) 评论(0) 推荐(0) 编辑

poj 1218 THE DRUNK JAILER

摘要: #include<iostream>using namespace std;int list[101];int main(){ int t,n,i,round,sum; cin>>t;while(t--) { cin>>n; memset(list,0,sizeof(list)); for(round=1;round<=n;round++) for(i=round;i<=n;i+=round) list[i]++; sum=0; for(i=1;i<=n;i++) if(list[i]%2) sum++; cout<<sum&l 阅读全文

posted @ 2011-07-17 23:55 sysu_mjc 阅读(89) 评论(0) 推荐(0) 编辑

poj 1247 Magnificent Meatballs

摘要: #include <iostream>using namespace std;int main(){ int n,list[31],total,i; while(cin>>n&&n) { total=0; for( i=1;i<=n;i++) { cin>>list[i]; total+=list[i]; } if(total%2!=0) cout<<"No equal partitioning.\n"; else { total/=2; int sum=0; for( i=1;;i++) { sum+= 阅读全文

posted @ 2011-07-17 23:55 sysu_mjc 阅读(80) 评论(0) 推荐(0) 编辑

poj 1207 The 3n + 1 problem

摘要: #include <iostream>using namespace std;int cycle(int n){ int t=1; while(n!=1) { if(n%2) n=3*n+1; else n/=2; t++; } return t;}int main(){ int i,j,k,max,m,tag; while(cin>>i>>j) { tag=0; if(i>j) { tag=1; swap(i,j); } max=1; for(k=i;k<=j;k++) { if(cycle(k)>max) m=k,max=cycle(k 阅读全文

posted @ 2011-07-17 23:54 sysu_mjc 阅读(120) 评论(0) 推荐(0) 编辑

poj 1171 Letter Game

摘要: #include <iostream>#include <string>using namespace std;struct node{ char words[10]; int len,val;}dic[40010];int c_fre[26],value[26] = {2,5,4,4,1,6,5,5,1,7,6,3,5,2,3,5,7,2,1,2,4,6,6,7,5,7};char coll[10],lett[10];int to_value(char ch[]){ int s=0; for(int i=0;i<strlen(ch);++i) s+=value[ 阅读全文

posted @ 2011-07-17 23:53 sysu_mjc 阅读(220) 评论(0) 推荐(0) 编辑

poj 1159 Palindrome

摘要: #include <iostream> // DP + 滚动数组#include <string>using namespace std;#define MAXN 5005int ans[2][MAXN];int main(){ int n; char s[MAXN]; scanf("%d%s",&n,s); for (int i=n-1;i>=0;--i) // 注意i是从大到小,因为求解ans[i][j]过程需要先知道ans[i+1][j] { for (int j=i+1;j<n;++j) { ... 阅读全文

posted @ 2011-07-17 23:52 sysu_mjc 阅读(116) 评论(0) 推荐(0) 编辑

poj 1163 The Triangle

摘要: #include<iostream>using namespace std;int n,triangle[101][101],tmp[101][101];int highest(int ii,int jj){ if(ii==n) return triangle[ii][jj]; if(tmp[ii][jj]!=-1) return tmp[ii][jj]; int a,b; a=(triangle[ii][jj]+highest(ii+1,jj)); b=(triangle[ii][jj]+highest(ii+1,jj+1)); tmp[ii][jj]=a>b?a:b; r 阅读全文

posted @ 2011-07-17 23:52 sysu_mjc 阅读(115) 评论(0) 推荐(0) 编辑

poj 1146 ID Codes

摘要: #include<iostream>#include<algorithm>#include<string>using namespace std;int main(){ string line; while(cin>>line&&line!="#") { if(next_permutation(line.begin(),line.end())) cout<<line<<endl; else cout<<"No Successor\n"; }return 0 阅读全文

posted @ 2011-07-17 23:51 sysu_mjc 阅读(97) 评论(0) 推荐(0) 编辑

poj 1141 Brackets Sequence

摘要: #include<iostream>#include <string>#define max 9999using namespace std;char s[110];int ans[110][110],pipei[110][110];void output(int x,int y){ if(x>y) return ; else if(x==y) { if(s[x]=='('||s[x]==')') printf("()"); else printf("[]"); } else { if(pip 阅读全文

posted @ 2011-07-17 23:50 sysu_mjc 阅读(155) 评论(0) 推荐(0) 编辑

poj 1125 Stockbroker Grapevine

摘要: // 题意: 给定n个人,求出从谁开始传递消息,使得所有人都知道这个消息所花费的时间最短,// 最短时间是多少?如果网络不通,就输出disjoint// 思路: 实际上是求最短路,先用floyd算法求出两两最短路,// 再求出从每个点开始的最长路,最后这n个最长路中的最小值即是答案#include <iostream> //floyd算法,每对顶点之间的最短路径using namespace std; #define inf 100000 #define maxn 102int distF[maxn][maxn]... 阅读全文

posted @ 2011-07-17 23:48 sysu_mjc 阅读(175) 评论(0) 推荐(0) 编辑

poj 1118 Lining Up

摘要: #include<iostream>using namespace std;double c[702][2];//坐标数组double k[702];//斜率数组int cmp( const void* a , const void* b ) { return *(double *)a > *(double *)b ? 1 : -1; } int main(){ int n,cnt,max,num; while(cin >> n) { if(n == 0)break; for(int i = 1;i <= n; ++i) cin >> c[i][ 阅读全文

posted @ 2011-07-17 23:47 sysu_mjc 阅读(143) 评论(0) 推荐(0) 编辑

poj 1068 Parencodings

摘要: #include<iostream>#include<memory.h>using namespace std;int list[44],paren[44],stack_paren[22]; void f(int n){ int i,j,w,top; memset(paren,-1,sizeof(paren)); //paren数组中-1表示(, 1表示) list[0]=0;top=0;w=0; for(i=1;i<=n;i++) { cin>>list[i]; w+=list[i]-list[i-1]+1; paren[w]=1; stack_pa 阅读全文

posted @ 2011-07-17 23:45 sysu_mjc 阅读(87) 评论(0) 推荐(0) 编辑

poj 1065 Wooden Sticks

摘要: #include <iostream>using namespace std;struct wood { int w; int l;}Wood[5000];int cmp(const void *a,const void *b){ if((*(wood*)a).l==(*(wood*)b).l) //不能写成(wood*)a->l,要写成(*(wood*)a).l return (*(wood*)a).w-(*(wood*)b).w; return (*(wood*)a).l-(*(wood*)b).l;}//按木棍的长度从小到大排序,当木棍长度相等时,按重量小到大排序。这样 阅读全文

posted @ 2011-07-17 23:43 sysu_mjc 阅读(121) 评论(0) 推荐(0) 编辑

poj 1061 青蛙的约会

摘要: // 题意: 解同余方程 (m-n)t≡y-x(mod L),求出t的最小解#include<iostream>using namespace std;int x_0,y_0,q; void extend_eulid(int a,int b) //x_0*a+y_0*b=gcd(a,b)=q{ if(b==0) { x_0=1;y_0=0;q=a; } else { extend_eulid(b,a%b); int temp=x_0; x_0=y_0;y_0=tem... 阅读全文

posted @ 2011-07-17 23:41 sysu_mjc 阅读(116) 评论(0) 推荐(0) 编辑

poj 1051 P,MTHBGWB

摘要: #include<iostream>#include<map>#include<string>using namespace std;map<char,string>col;map<char,string>::iterator ite;void f(string str){ string ss,temp; int i,top=0,len_pre=0,len[101]; for(i=0;i<str.size();i++) { ite=col.find(str[i]); ss.append(ite->second); len[ 阅读全文

posted @ 2011-07-17 23:40 sysu_mjc 阅读(184) 评论(0) 推荐(0) 编辑

poj 1042 Gone Fishing

摘要: #include<iostream>using namespace std;const int iMax = 30;const int jMax = 200;/*首先是贪心的思路:枚举所经过的湖的个数k,每种情况减去所需步行的时间,剩下的就是钓鱼的时间了,之后就只需要在所剩的时间内使钓鱼数最大,因此每次选择最多鱼的湖点,最后构造起时间段。*//*解此题的主要方法是枚举+贪心。刚开始的时候还没想到一个好方法,因为当前鱼最多的池塘是变化的,而题目所给描述里面的钓鱼又是有顺序的,即:John starts at lake 1, but he can finish at any lake 阅读全文

posted @ 2011-07-17 23:38 sysu_mjc 阅读(167) 评论(0) 推荐(0) 编辑

poj 1050 To the Max

摘要: #include<iostream>using namespace std;int rec[101][101];int sub(int ii,int jj,int len,int wid){ int sum=0; for(int i=ii;i<=len;i++) for(int j=jj;j<=wid;j++) sum+=rec[i][j]; return sum;}int main(){ int i,j,n,max=-200,ll,ww,s; cin>>n; for (i=1;i<=n;i++) for(j=1;j<=n;j++) { scan 阅读全文

posted @ 2011-07-17 23:38 sysu_mjc 阅读(88) 评论(0) 推荐(0) 编辑

导航