上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 57 下一页

2011年7月22日

poj 2503 Babelfish

摘要: // 题意: 给出一组字符串对(s1,s2),和待查询的单词s2,输出单词s2的对应字符串s1,如果找不到则输出‘eh’#include <iostream> // trie树#include <string>using namespace std ;#define maxn 100100struct Node { int next[26]; int pos; //记录该节点所代表的字符串出现的位置,若pos=-1则说明从未出现过}table[1000100]; //maxn*10,因为每个单词至多10个字母int cur;void ini... 阅读全文

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

poj 2524 Ubiquitous Religions

摘要: // 题意:一个学校有n人,其中有m对人是具有相同的宗教信仰,问这个学校里有多少种不同的宗教信仰#include <iostream> //并查集 using namespace std;int p[50010],hei[50010],n,m;void init(){ for(int i=1;i<=n;++i) { p[i]=i; hei[i]=0; }}//路径压缩,当我们经过"递归"找到祖先节点后,"回溯"的时候顺便将路径上的所有节点都直接指向祖先int find(int x){ return p[x]==x ? x ... 阅读全文

posted @ 2011-07-22 15:06 sysu_mjc 阅读(120) 评论(0) 推荐(0) 编辑

poj 2413 How many Fibs?

摘要: #include <iostream>#include <string>using namespace std;bool compare(string str1,string str2){ if(str1.size()==str2.size()) return str1>=str2; else return str1.size()>str2.size();}string ADD_INT(string str1, string str2) { string str; string::size_type l1, l2; int i; l1 = str1.size 阅读全文

posted @ 2011-07-22 15:04 sysu_mjc 阅读(143) 评论(0) 推荐(0) 编辑

poj 2492 A Bug's Life

摘要: // 题意:有种虫只有两种性别,它们只和不同性别的虫配对,给出n对异性虫,判断是否冲突#include <iostream> //并查集using namespace std;int p[2002],diff[2002],n,m; //diff[i]=j表示编号为j跟编号为i的人不在同一组void init(){ for(int i=1;i<=n;++i) { p[i]=i; diff[i]=-1; }}int find(int x){ return p[x]==x ? x : p[x]=find(p[x]);}v... 阅读全文

posted @ 2011-07-22 15:04 sysu_mjc 阅读(140) 评论(0) 推荐(0) 编辑

poj 2402 Palindrome Numbers

摘要: #include <iostream>#include <string>#include <math.h>using namespace std;__int64 list[20]={0,9,9,90,90,900,900,9000,9000,90000,90000,900000,900000,9000000,9000000,90000000,90000000,900000000,900000000,9000000000};//list[i]表示位数为i的满足回文数要求共有list[i]个int main(){ __int64 n,sum; int i; wh 阅读全文

posted @ 2011-07-22 15:03 sysu_mjc 阅读(136) 评论(0) 推荐(0) 编辑

poj 2304 Combination Lock

摘要: #include <iostream> //水题using namespace std;//是外表盘在转而指针不转,如果将外表盘固定,指针相对于外表盘顺逆方向刚好相反,i.e.,他描述的顺时针方向,指针其实转向逆时针,//所以顺序应该是(1)逆(2)顺(3)逆int main(){ int location[4],sum; while(cin>>location[0]>>location[1]>>location[2]>>location[3]) { if(location[0]+location[1]+location[2]+loc 阅读全文

posted @ 2011-07-22 15:02 sysu_mjc 阅读(186) 评论(0) 推荐(0) 编辑

poj 2309 BST

摘要: #include <iostream> //第n层表示元素可以被2^n整除,从第0层开始,第n层的元素的subtree范围为a-(2^n-1) , a+(2^n-1)#include <math.h>using namespace std;int main(){ int n,count; __int64 a,tmp; cin>>n; while(n--) { cin>>a; tmp=a; count=0; while(tmp%2==0) { count++; tmp=tmp/2; } cout<<a-(__int64)pow(2.0, 阅读全文

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

poj 2299 Ultra-QuickSort

摘要: 求逆序对数,树状数组+离散化#include <iostream> //求逆序对数,树状数组+离散化,ac#include <algorithm>using namespace std;int tree[500001],list[500001],n,maxn=500000;__int64 amount;struct node { __int64 val; int id; bool operator<(const node& z)const { return val<z.val; }}sequence[500001];void hash() //离散化 阅读全文

posted @ 2011-07-22 15:01 sysu_mjc 阅读(135) 评论(0) 推荐(0) 编辑

poj 2262 Goldbach's Conjecture

摘要: #include <iostream> using namespace std;int prime[100000],end;bool test(int a){ if(a%2==0) return false; for(int i=3;i*i<=a;i+=2) { if(a%i==0) return false; } return true;}void init(){ int j=0; for(int i=3;i<=1000003;++i) { if(test(i)) prime[j++]=i; } end=j-1;}int find(int n){ int b=0,e= 阅读全文

posted @ 2011-07-22 14:59 sysu_mjc 阅读(123) 评论(0) 推荐(0) 编辑

poj 2236 Wireless Network

摘要: // 题意:有n台损坏的电脑,在两种情况下已修复电脑能相互通信,// 一是他们之间的距离小于d,二是他们可以借助都可到达的第三台已修复的电脑。// 给出所有电脑的坐标位置,两种操作: O x 表示修复第x台, S x y 表示判断x y之间能否通信#include <iostream> //并查集using namespace std;#define maxn 1002int p[maxn];int g[maxn][maxn],pos[maxn][2],work[maxn],n,d;int near(int i,int j) //判断节点i与j是否连通{ int d... 阅读全文

posted @ 2011-07-22 14:57 sysu_mjc 阅读(106) 评论(0) 推荐(0) 编辑

上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 57 下一页

导航