上一页 1 ··· 31 32 33 34 35 36 37 38 39 ··· 57 下一页

2011年7月20日

poj 2159 Ancient Cipher

摘要: #include <iostream>#include <string>#include <algorithm>using namespace std;int res[26],origin[26];int main(){ string str1,str2; bool flag=true; int i; cin>>str1>>str2; for(i=0;i<str1.size();++i) { res[str1[i]-65]++; origin[str2[i]-65]++; } sort(res,res+26); sort(ori 阅读全文

posted @ 2011-07-20 22:48 sysu_mjc 阅读(108) 评论(0) 推荐(0) 编辑

poj 2153 Rank List

摘要: #include <iostream> //The rank is decided by the total scores. 分数要累加#include <string>#include <map>using namespace std;int main(){ int n,m,i;string name; map<string,int> score; map<string,int>::iterator pos; scanf("%d\n",&n); for(i=1;i<=n;++i) { getline 阅读全文

posted @ 2011-07-20 22:47 sysu_mjc 阅读(104) 评论(0) 推荐(0) 编辑

poj 2155 Matrix

摘要: /* 题意: 给定一个0-1矩阵,在线对在范围[x1,y1]-[x2,y2]之内的元素置反,在线求[x,y]元素值 思路: 表面上看,这题的要求似乎和树状数组的使用方法恰好相反,改变的是一个区间,查询的反而是一个点。 实际上可以通过一个转化巧妙的解决。 首先对于每个数A定义集合up(A)表示{A, A+lowbit(A), A+lowbit(A)+lowbit(A+lowbit(A))...} 定义集合down(A)表示{A, A-lowbit(A), A-lowbit(A)-lowbit(A-lowbit(A)) ... , 0}。 可以发现对于任何A<B,up(A)和down(B)的 阅读全文

posted @ 2011-07-20 22:47 sysu_mjc 阅读(157) 评论(0) 推荐(0) 编辑

poj 2104 K-th Number

摘要: 自定义快排 #include <iostream>using namespace std;struct node { int index; int num;}list[100000];int part(int beg,int end){ int low=beg,high=end; node pivot=list[beg]; while(low < high) { while(low<high && list[high].num>=pivot.num) --high; list[low].index=list[high].index; list[lo 阅读全文

posted @ 2011-07-20 22:46 sysu_mjc 阅读(154) 评论(0) 推荐(0) 编辑

poj 1915 Knight Moves

摘要: // 题意:图的大小L*L,可以向 8 个方向移动,求起点到终点的最短移动距离 #include <iostream> // BFS#include <string.h>using namespace std;const int MAXL=300;int q[MAXL*MAXL],vis[MAXL][MAXL],dist[MAXL][MAXL];const int dx[]={-1,-2,-2,-1,1,2,2,1}; const int dy[]={-2,-1,1,2,2,1,-1,-2};int L,sx,sy,tx,ty;void bfs(){ vis[sx][. 阅读全文

posted @ 2011-07-20 22:45 sysu_mjc 阅读(113) 评论(0) 推荐(0) 编辑

poj 1384 Piggy-Bank

摘要: #include <iostream> //dpusing namespace std;#define MAX 999999int dp[10000],weight[510],value[510];int main(){ int t,e,f,n; int i,j,total,min_w; scanf("%d",&t); while (t--) { scanf("%d%d%d",&e,&f,&n); total=f-e; min_w=MAX; for(i=0;i<n;i++) { scanf("% 阅读全文

posted @ 2011-07-20 22:44 sysu_mjc 阅读(118) 评论(0) 推荐(0) 编辑

poj 1350 Cabric Number Problem

摘要: #include <iostream>#include <algorithm>#include <vector>#include <string>#include <math.h>using namespace std;int to_int(vector<char> coll){ int sum=0; for(int i=0;i<coll.size();i++) sum+=(coll[i]-48)*pow(10.0,i); return sum;}void to_vec(vector<char>& 阅读全文

posted @ 2011-07-20 22:39 sysu_mjc 阅读(134) 评论(0) 推荐(0) 编辑

poj 1338 Ugly Numbers

摘要: #include <iostream>using namespace std;int factor[3]={2,3,5},prime[1510]={1};int start[3];int main(){ int i,j,min,n; for(i=1;i<1510;i++) { min=2147483647; for(j=0;j<3;j++) if(prime[start[j]]*factor[j]<min) min=prime[start[j]]*factor[j]; prime[i]=min; for(j=0;j<3;j++) if(prime[start 阅读全文

posted @ 2011-07-20 22:38 sysu_mjc 阅读(108) 评论(0) 推荐(0) 编辑

poj 1318 Word Amalgamation

摘要: #include <iostream>#include <string>#include <set>using namespace std;bool match(string str1,string str2){ for(int i=0;i<str1.size();++i) { if(str2.find_first_of(str1[i])==string::npos) return false; else str2.erase(str2.find_first_of(str1[i]),1); } return true;}int main(){ stri 阅读全文

posted @ 2011-07-20 22:37 sysu_mjc 阅读(164) 评论(0) 推荐(0) 编辑

poj 1308 Is It A Tree?

摘要: // 题意: 给出一些边,由所给出的边能否构成一棵树.(节点数<100)// 思路: n个顶点的树具有3个特点:连通,不含环,恰好包含n-1条边.只要有任意两个,就能推导出第3个// 所以我们可以通过是否连通和不含环来判断可以构成树.// 不含环: 通过并查集,如果边a->b, a和b的祖先结点都一样,则是有环,包括a->a,和 a->b 重复出现,// 连通: 只有一个根结点#include <iostream> //并查集using namespace std;#define maxn 1000int p[maxn],isNode[maxn];int f 阅读全文

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

上一页 1 ··· 31 32 33 34 35 36 37 38 39 ··· 57 下一页

导航