2011年7月20日

poj 3210 Coins

摘要: #include <iostream>using namespace std;int main(){ int n; while(scanf("%d",&n)&&n) { if(n%2==0)printf("No Solution!\n"); else printf("%d\n",n-1); } return 0;}/*1.若N为偶数。若初始状态为硬币全部同面的话,则翻转次数为偶数 (0+2*i,i=0,1,2... 对一枚硬币可以翻任意2*i次 )正反面硬币的组合可能是(奇数+奇数)或者(偶数+偶数 阅读全文

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

poj 2591 Set Definition

摘要: #include <iostream> //参照poj 2247using namespace std;int prime[10000000],start[2]; //这里的数组开得较大,如果写成prime[10000000]={1};在POJ编译器上会产生错误:/*Compile ErrorMain.cppMain.exe : fatal error LNK1106: invalid file or disk full: cannot seek to 0x2646748*/int main(){ int i,n; prime[0]=1; for(i=1;i<10000000 阅读全文

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

poj 2545 Hamming Problem

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

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

poj 2586 Y2K Accounting Bug

摘要: #include <iostream> //贪心using namespace std;int months[20];int main(){ int d,s,i,j,sum,total; while(cin>>s>>d) { if(s>=4*d) printf("Deficit\n"); else { d*=-1; for(i=0;i<4;++i) months[i]=d; for(i=4;i<16;++i) { months[i]=s; sum=0; for(j=i-4;j<=i;++j) sum+=months 阅读全文

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

poj 2528 Mayor's posters

摘要: /* 题意:往区间[1,10000000]的墙上贴海报,海报数量<=10000, 海报之间彼此可以覆盖,问最后能看到的海报数量。 考虑到区间太大,直接线段树无疑会MLE,所以要对其离散化,再用线段树。 基本做法是先对所有端点坐标进行排序,用相应序号代替端点坐标构造线段树进行计算。 这样最大的序号也只是2*10000,这样就减少了没必要的搜索的时间和内存空间。 同时为了提高效率,采取倒插入的方式,即从数据的最后一行开始处理,在插入的同时进行判断。 在统计覆盖的时候,采用倒插入的方式从树的根开始进行统计*/#include <iostream> // 线段树+离散化#includ 阅读全文

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

poj 2362 Square

摘要: #include <iostream> //参照poj 1011 sticks#include <algorithm>using namespace std;int sticks[20],visited[20];int flag,total;int t,seg;int cmp(const void* a,const void* b){ return (*(const int*)b)-(*(const int *)a);}void solve(int k,int sum,int cnt) { if(cnt==4) flag=true; else if(sum==seg) 阅读全文

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

poj 2407 Relatives

摘要: #include <iostream> //利用欧拉函数φ(n),求出跟n互质且小于n的正整数的个数using namespace std;int main () { int n,j,phi; while(scanf("%d",&n)&&n) { phi=1; for(j=2;j*j<=n;j++) //j是逐步增加的,因为一次while循环会完全排除掉一个素数因子,所以剩下的素数因子值肯定更大,这里j的取值范围本身是按照判断素数 { if(n%j!=0)continue; while(n%j==0) //能进入循环内的j一定是素数 阅读全文

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

poj 2247 Humble Numbers

摘要: #include <iostream>using namespace std;int start[4],prime[5843]={1};int factor[4]={2,3,5,7};int main(){ int i,j,min; for(i=1;i<=5842;i++) { min=2000000001; for(j=0;j<4;j++) if(prime[start[j]]*factor[j]<=min) //不要漏掉=的情况 min=prime[start[j]]*factor[j]; prime[i]=min; for(j=0;j<4;j++) i 阅读全文

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

poj 2352 Stars

摘要: #include <iostream> //树状数组using namespace std;int tree[32010],level[15010];int lowbit(int x){ return x&(-x);}void modify(int x){ while(x<32010) { tree[x]++; x+=lowbit(x); }}int sum(int x){ int s=0; while(x>0) { s+=tree[x]; x-=lowbit(x); } return s;}int main(){ int n,i,x,y; cin>> 阅读全文

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

poj 2192 Zipper

摘要: //给出三个字符串,判断第三个字符串是否可以由前两个字符串组成,//注意前两个字符串中的字母在新组成的字符串中的顺序和在原来字符串中的顺序一样.#include <iostream>#include<stdio.h>#include<cstring>using namespace std;char s1[210],s2[210],goal[410];int f[210][210]; //记录状态//f[i][j]有三种可能取值,-1表示初始化,即不清楚能否匹配成功,0表示匹配不成功,1表示匹配成功bool match(int i,int j) //判断s1的 阅读全文

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

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) 编辑

导航