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

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

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

导航