上一页 1 ··· 34 35 36 37 38 39 40 41 42 ··· 57 下一页

2011年7月18日

poj 3687 Labeling Balls

摘要: // 题意:有n个球, 重量分别为1-n, 给出一组(a,b)对,表示编号为a的小球比b小球要轻,小球的编号是1-n // 依次输出编号从1到n的球的重量, 要求编号小的球(即靠前的小球)的重量要尽量轻.// 反向建图,有向边heavy->light,逆拓扑排序,从重到轻逐一确定#include <iostream> //逆拓扑排序,从重到轻逐一确定using namespace std;int topo[201][201],in[201],w[201]; int main(){ int cases,n,m; cin>>cases; whi... 阅读全文

posted @ 2011-07-18 11:44 sysu_mjc 阅读(125) 评论(0) 推荐(0) 编辑

poj 2739 Sum of Consecutive Prime Numbers

摘要: #include <iostream>#include <math.h>using namespace std;int prime[2000];bool isprime(int n){ for(int i=2;i<=sqrt(n+0.0);i++) if(n%i==0)return false; return true;}int main(){ int i,j,end,s,top=0; for(i=2;i<10000;i++) { if(isprime(i)) prime[top++]=i; } int n,con; while(scanf("%d 阅读全文

posted @ 2011-07-18 11:44 sysu_mjc 阅读(134) 评论(0) 推荐(0) 编辑

poj 2719 Faulty Odometer

摘要: #include <string>#include<iostream>#include <math.h>using namespace std;int main(){ string str;int i,a,s; while(cin>>str&&str[0]!='0') { s=0; for(i=0;i<str.size();i++) { a=str[i]-48; if(a>4)a--; s+=a*pow(9,str.size()-i-1.0); } cout<<str<<&quo 阅读全文

posted @ 2011-07-18 11:43 sysu_mjc 阅读(112) 评论(0) 推荐(0) 编辑

poj 2593 Max Sequence

摘要: #include <iostream> //参照 POJ 2479using namespace std;#define MAX 100001int list[MAX],left_sum[MAX],right_sum[MAX]; //要声明为全局变量,如果在主函数内声明,会产生堆栈溢出int main(){ int n,i; while(scanf("%d",&n)&&n) { for(i=1;i<=n;i++) scanf("%d",&list[i]); left_sum[1]=list[1]; for 阅读全文

posted @ 2011-07-18 11:42 sysu_mjc 阅读(114) 评论(0) 推荐(0) 编辑

poj 2406 Power Strings

摘要: #include <iostream> //KMP算法using namespace std;char B[2000000]; int m,next[2000000]; void get_next(){ next[1]=0; int j=0; for(int i=2;i<=m;++i) { while(j>0&&B[j+1]!=B[i]) j=next[j]; if(B[j+1]==B[i]) j=j+1; next[i]=j; }}int main(){ while(scanf("%s",B+1)&&B[1]!=&# 阅读全文

posted @ 2011-07-18 11:41 sysu_mjc 阅读(122) 评论(0) 推荐(0) 编辑

poj 2479 Maximum sum

摘要: #include<iostream>#include<stdio.h>using namespace std;int num[50010],l[50010],r[50010];#define Min -9999999int main(){ int T,n,sum,tmp; cin>>T; while(T--) { scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&num[i]); sum=0;tmp=Min; //l[i]表示[1,i]中最大的子段 阅读全文

posted @ 2011-07-18 11:41 sysu_mjc 阅读(109) 评论(0) 推荐(0) 编辑

poj 2140 Herd Sums

摘要: #include <iostream>using namespace std;int main(){ int i,n; int counts=0; scanf("%d",&n); for(i=1;i<=n/2;i+=2) //当i=1表示只由原数单独构成 if(n%i==0) counts++; if(n%2!=0) counts++; printf("%d\n",counts); return 0;}//只要是连续的数相加,则和 n 都可化成 一个奇数 i 乘以 某个数 a//比如: 1+2+3+4 = 5 * 2 ( 5 = 阅读全文

posted @ 2011-07-18 11:40 sysu_mjc 阅读(157) 评论(0) 推荐(0) 编辑

poj 2136 Vertical Histogram

摘要: #include <iostream>#include<string>using namespace std;int letter[27];int main(){ string str;int i,j; for( i=0;i<4;i++) { getline(cin,str); for( j=0;j<str.size();j++) if(str[j]>=65&&str[j]<=90) letter[str[j]-64]++; } int max=0; for(i=1;i<=26;i++) if(letter[i]>ma 阅读全文

posted @ 2011-07-18 11:39 sysu_mjc 阅读(141) 评论(0) 推荐(0) 编辑

poj 2105 IP Address

摘要: #include <iostream>#include <string>#include <math.h>using namespace std;void to_decimal(string s,int begin,int end){ int sum=0,j=7; for(int i=begin;i<=end;i++) sum+=pow(2.0,j--)*(s[i]-48); cout<<sum;}int main(){ string str; int t,p; cin>>t; while(t--) { cin>>s 阅读全文

posted @ 2011-07-18 11:38 sysu_mjc 阅读(94) 评论(0) 推荐(0) 编辑

poj 2081 Recaman's Sequence

摘要: #include <iostream> using namespace std;int list[500001];bool flag[10000000];int main(){ int n,top=0; fill(flag,flag+sizeof(flag),1); list[0]=0;flag[0]=0; while(scanf("%d",&n)&&n!=-1) { while(top<n) { if(list[top]-top-1>0&&flag[list[top]-top-1]) { top++; lis 阅读全文

posted @ 2011-07-18 11:37 sysu_mjc 阅读(90) 评论(0) 推荐(0) 编辑

上一页 1 ··· 34 35 36 37 38 39 40 41 42 ··· 57 下一页

导航