08 2012 档案

删数字
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int i,n,num,tail,head; 5 char q[100],s[100]; 6 while(~scanf("%s%d",s,&n)){ 7 tail=head=num=i=0; 8 q[tail++]=s[i++]; 9 while(s[i]){10 if(s[i]>q[tail-1]||num>=n)11 q[tail++]=s[i++];12 el... 阅读全文

posted @ 2012-08-23 16:36 小花熊 阅读(161) 评论(0) 推荐(0) 编辑

hdu3339 In Action
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #define Max 0x3f3f3f3f 4 int n,m,totalEle,miCost; 5 bool vis[101]; 6 int map[101][101],dist[101]; 7 int d[10001],val[101]; 8 void init()//初始化读入数据 9 {10 int i,j,a,b,w;11 scanf("%d%d",&n,&m);12 for(i=0;i<=n;++i)13 for(j=0;j< 阅读全文

posted @ 2012-08-23 16:28 小花熊 阅读(199) 评论(0) 推荐(0) 编辑

hdu2159 FATE
摘要:1 #include<stdio.h> 2 #include<string.h> 3 int d[101][101]; 4 int main() 5 { 6 int i,j,t,flag,v,w,n,m,k,s; 7 while(~scanf("%d%d%d%d",&n,&m,&k,&s)){ 8 memset(d,0,sizeof(d)); 9 for(flag=i=0;i<k;++i){10 scanf("%d%d",&v,&w);11 for(j=w;j<=m;++ 阅读全文

posted @ 2012-08-23 14:53 小花熊 阅读(182) 评论(0) 推荐(0) 编辑

hdu1114 Piggy-Bank
摘要:1 #include<stdio.h> 2 int d[10010]; 3 int main() 4 { 5 int i,j,n,pig,total,v,w,T; 6 scanf("%d",&T); 7 while(T--) 8 { 9 scanf("%d%d%d",&pig,&total,&n);10 total-=pig;11 memset(d,0x3f,sizeof(d));12 for(d[0]=0,i=0;i<n;++i){13 scanf("%d%d",&v,&am 阅读全文

posted @ 2012-08-23 14:52 小花熊 阅读(143) 评论(0) 推荐(0) 编辑

poj1017 Packets
摘要:1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int i,t,n; 6 int a[7],f[7]; 7 while(1) 8 { 9 memset(f,0,sizeof(f));10 for(n=0,i=1;i<=6;++i){11 scanf("%d",&a[i]);12 n+=a[i];13 }14 if(!n) break;15 for(... 阅读全文

posted @ 2012-08-23 11:00 小花熊 阅读(176) 评论(0) 推荐(0) 编辑

hdu1385 Minimum Transport Cost
摘要:1 #include<stdio.h> 2 #define Max 0xfffffff 3 #define N 600 4 bool vis[N]; 5 int path[N][N];//昨天把path数组定义为BOOl型了,输出的时候老是死循环,昨天检查了一晚上没发现,今天多亏了我强悍的队友给我指明了错误!! 6 int d[N][N],cost[N]; 7 int vexnum,arcnum; 8 void floyd() 9 {10 for(int k=0;k<vexnum;++k)11 for(int i=0;i<vexnum;++i)12 ... 阅读全文

posted @ 2012-08-22 10:52 小花熊 阅读(169) 评论(0) 推荐(0) 编辑

hdu2602 Bone Collector
摘要:1 #include<iostream> 2 using namespace std; 3 int f[1001][1001],w[1001],v[1001]; 4 int main() 5 { 6 int i,j,n,totalv,T; 7 cin>>T; 8 while(T--){ 9 cin>>n>>totalv;10 for(i=1;i<=n;++i)11 cin>>v[i];12 for(i=1;i<=n;++i)13 cin>>w[i];14 f... 阅读全文

posted @ 2012-08-22 10:40 小花熊 阅读(210) 评论(0) 推荐(0) 编辑

poj3767 I Wanna Go Home
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #define Max 0xfffffff 5 int m[610][610],p[610]; 6 bool vis[610]; 7 bool leader[610]; 8 int vexnum,arcnum; 9 void dijkstra()10 {11 int i,j,k,t,min;12 memset(vis,0,sizeof(vis));13 for(i=1;i<=vexnum;++i)14 p[i]=m[1][i] 阅读全文

posted @ 2012-08-21 17:14 小花熊 阅读(203) 评论(0) 推荐(0) 编辑

hdu2544 最短路
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #define Max 0xfffffff 5 int m[10010][10010],p[10010]; 6 bool vis[10010]; 7 int vexnum,arcnum; 8 void dijstra() 9 {10 int i,j,k,t,min;11 memset(vis,0,sizeof(vis));12 for(i=1;i<=vexnum;++i)13 p[i]=m[1][i];14 for(v... 阅读全文

posted @ 2012-08-21 15:49 小花熊 阅读(203) 评论(0) 推荐(0) 编辑

hdu1421 搬寝室
摘要:1 #include<cstring> 2 #include<iostream> 3 #include<algorithm> 4 #define P(x,y) ((x-y)*(x-y)) 5 using namespace std; 6 int a[2010],d[2010][2010]; 7 int main() 8 { 9 int i,j,n,k;10 while(cin>>n>>k){11 for(i=0;i<n;++i)12 cin>>a[i];13 sort(a,a+n);14 memset(d... 阅读全文

posted @ 2012-08-21 14:40 小花熊 阅读(178) 评论(0) 推荐(0) 编辑

nyoj20 吝啬的国度
摘要:1 #include<queue> 2 #include<vector> 3 #include<cstdio> 4 #include<cstring> 5 #include<iostream> 6 using namespace std; 7 queue<int> q; 8 int f[100010]; 9 vector<int> m[100010];//不能用二维数组,否则一直超内存,用vector定义二维数组虽然不超内存,但超时,因为它在定义是很耗时间 10 int main()11 {12 int i,a 阅读全文

posted @ 2012-08-20 14:41 小花熊 阅读(642) 评论(0) 推荐(0) 编辑

hdu1274 展开字符串
摘要:1 #include<stdio.h> 2 #include<ctype.h> 3 #include<string.h> 4 char s[260]; 5 int dfs(int ith) 6 { 7 int k,e; 8 char c; 9 for(c=s[ith++];ith<strlen(s)&&c!=')';c=s[ith++])//递归结束的条件是字符串结束或遇到右括号 10 {11 for(k=0;isdigit(c);c=s[ith++])12 k=k*10+c-'0';13 if(!k) 阅读全文

posted @ 2012-08-18 10:40 小花熊 阅读(551) 评论(0) 推荐(0) 编辑

hdu递推公式水题
摘要:hdu2013蟠桃记 1 #include<stdio.h> 2 int main() 3 { 4 long long day,x,ans[31]; 5 for(int i=1;i<31;++i){ 6 x=1; 7 day=i; 8 while(--day) 9 x=(x+1)<<1;10 ans[i]=x;11 }12 while(~scanf("%I64d",&day))13 printf("%I64d\n",ans[day]);14 retu... 阅读全文

posted @ 2012-08-18 10:12 小花熊 阅读(224) 评论(0) 推荐(0) 编辑

nyoj58 最少步数
摘要:1 #include<stdio.h> 2 int ans,sx,sy,ex,ey; 3 bool vis[9][9],map[9][9]={ 4 1,1,1,1,1,1,1,1,1, 5 1,0,0,1,0,0,1,0,1, 6 1,0,0,1,1,0,0,0,1, 7 1,0,1,0,1,1,0,1,1, 8 1,0,0,0,0,1,0,0,1, 9 1,1,0,1,0,1,0,0,1,10 1,1,0,1,0,1,0,0,1,11 1,1,0,1,0,0,0,0,1,12 1,1,1,1,1,1,1,1,113 };14 void dfs(int i,int j,in... 阅读全文

posted @ 2012-08-17 23:22 小花熊 阅读(311) 评论(0) 推荐(0) 编辑

poj1691 Painting A Board
摘要:1 #include<cstring> 2 #include<iostream> 3 using namespace std; 4 struct node{ 5 int x1,y1,x2,y2,color; 6 }G[15]; 7 int n,ans,deg[15];//n表区域的个数,ans存储最终结果,deg存储拓扑图中各点的入度 8 bool vis[15],m[15][15];//vis用于标记是否访问过,m表示各点之间的联系 9 void buildG()//建立拓扑图,用于确定优先级 10 {11 for(int i=0;i<n;++i)12 ... 阅读全文

posted @ 2012-08-17 21:02 小花熊 阅读(423) 评论(0) 推荐(0) 编辑

全排列生成算法:next_permutation
摘要:概念全排列的生成算法有很多种,有递归遍例,也有循环移位法等等。但C++/STL中定义的next_permutation和prev_permutation函数则是非常灵活且高效的一种方法,它被广泛的应用于为指定序列生成不同的排列。本文将详细的介绍prev_permutation函数的内部算法。按照STL文档的描述,next_permutation函数将按字母表顺序生成给定序列的下一个较大的排列,直到整个序列为降序为止。prev_permutation函数与之相反,是生成给定序列的上一个较小的排列。二者原理相同,仅遍例顺序相反,这里仅以next_permutation为例介绍算法。先对序列大小的比 阅读全文

posted @ 2012-08-16 21:06 小花熊 阅读(959) 评论(0) 推荐(0) 编辑

一位ACMer过来人的心得
摘要:刻苦的训练我打算最后稍微提一下。主要说后者:什么是有效地训练?我想说下我的理解。很多ACMer入门的时候,都被告知:要多做题,做个500多道就变牛了。其实,这既不是充分条件、也不会是必要条件。我觉得一般情况下,对于我们普通学校的大学生,各方面能力的差距不会太大,在这种情况下,训练和学习的方法尤为重要。其实,500题仅仅是一个标志,而且仅仅表示你做ACM-ICPC有一定的时间,我们训练的目的是什么?我觉得有四点1、提高编程能力2、学习算法,(读书,读论文,包括做一些题目验证)3、准备好面临将到来的挑战(熟悉题型,调整心态)4、启发思维。这里四个目的,从训练的角度上,重要性逐次递减;为什么呢?因. 阅读全文

posted @ 2012-08-15 23:53 小花熊 阅读(310) 评论(1) 推荐(0) 编辑

oj2787 算24
摘要:1 #include<math.h> 2 #include<stdio.h> 3 #define Z 1e-6 //因为实数是否为0的判断不能用'==',而取而代之的是判断其是否小于一个很小的数,这里用10^(-6) 4 double a[4];//必须是double型的,我刚开始是用float,结果贡献了几个WA 5 bool f(int n) 6 { 7 if(n==1){//最后处理完毕,即到达解答树叶子节点 8 if(fabs(a[0]-24)<Z) return 1;//假如最后结果==24,则返回1 9 else return 0;.. 阅读全文

posted @ 2012-08-15 22:33 小花熊 阅读(268) 评论(0) 推荐(0) 编辑

oj2694 逆波兰表达式
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 double exp() 4 { 5 char a[10]; 6 scanf("%s",a); 7 switch(a[0]) 8 { 9 case '+': return exp()+exp();10 case '-': return exp()-exp();11 case '*': return exp()*exp();12 case '/': return exp()/exp();13 def... 阅读全文

posted @ 2012-08-15 19:29 小花熊 阅读(228) 评论(0) 推荐(0) 编辑

poj1979 Red and Black
摘要:1 #include<stdio.h> 2 char m[20][20]; 3 int r,c,count; 4 void cnt(int i,int j)//统计连续黑砖的块数 5 { 6 if(m[i][j]=='#'||(i<0||j<0)||(i>r-1||j>c-1))//边界条件,除去 7 return; 8 m[i][j]='#';//发现了一个新的黑砖,置'#',下次不在访问 9 count++; //count+110 cnt(i,j-1);//往左寻找 11 cnt(i-1,j);//往上寻 阅读全文

posted @ 2012-08-15 18:13 小花熊 阅读(193) 评论(0) 推荐(0) 编辑

oj2755 神奇的口袋
摘要:1 #include<stdio.h> 2 int n,a[20]; 3 int cnt(int i,int sum) 4 { 5 if(!sum) return 1;//如果sum等于0,说明前面已经找到一种成功的组合方式,返回1, 6 if(i==n||sum<0) return 0;//i==n,说明找遍了数组a,但没找到符合的,返回0,如果sum<0,此路径不符合,返回0。 7 return cnt(i+1,sum-a[i])+cnt(i+1,sum); 8 } 9 int main()10 {11 scanf("%d",&n);12 阅读全文

posted @ 2012-08-15 17:36 小花熊 阅读(207) 评论(0) 推荐(0) 编辑

poj1664 放苹果
摘要:1 #include<stdio.h> 2 inline int f(int m,int n)//m代表苹果数,n代表盘子数 3 { 4 if(m==0||n==1) return 1;//当没有苹果可放时,定义为1种放法;当n=1时,所有苹果都必须放在一个盘子里,所以返回1; 5 if(n>m) return f(m,m); 6 return f(m,n-1)+f(m-n,n);//递归的两条路,第一条n会逐渐减少,终会到达出口n==1; 第二条m会逐渐减少,因为n>m时,我们会return f(m,m) 所以终会到达出口m==0. 7 8 } 9 int ma... 阅读全文

posted @ 2012-08-15 17:14 小花熊 阅读(196) 评论(2) 推荐(0) 编辑

nyoj32 组合数
摘要:1 #include<stdio.h> 2 int a[10]; 3 void f(int n,int r)//r用来记录还有多少数字有待寻找 4 { 5 for(int i=n;i>0;--i){ 6 a[r]=i; 7 if(r>1) 8 f(i-1,r-1);//i-1不能换成n-1,否则会出现前面小于后面的情况,这样才能使得后面的绝对小于前面的 9 else{10 for(int j=a[0];j>0;--j)11 printf("%d",a[j... 阅读全文

posted @ 2012-08-15 16:15 小花熊 阅读(286) 评论(0) 推荐(0) 编辑

nyoj236 心急的C小加
摘要:1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 struct node{ 5 int l,w; 6 }stick[5001]; 7 bool cmp(node a,node b) 8 { 9 if(a.l!=b.l) return b.l>a.l;10 return b.w>a.w;11 }12 int main()13 {14 int i,j,n,cnt,T;15 cin>>T;16 while(T--)17 {18 for(cin... 阅读全文

posted @ 2012-08-15 12:42 小花熊 阅读(302) 评论(0) 推荐(0) 编辑

nyoj19 擅长排列的小明
摘要:1 #include<stdio.h> 2 int n,a[10]; 3 bool vis[10];//标示数字是否被用过 4 void f(int k,int m)//k用来给a中第k个元素赋值,m表示还需要寻找的数字个数 5 { 6 for(int i=1;i<=n;++i) 7 { 8 if(!vis[i]) a[k]=i; 9 else continue;//用过的 话找下个数字 10 vis[i]=1;//标志为1,下层递归不再使用 11 if(m>1)//m>1继续寻找12 ... 阅读全文

posted @ 2012-08-15 12:37 小花熊 阅读(243) 评论(0) 推荐(0) 编辑

poj1164 The Castle
摘要:1 #include<stdio.h> 2 int modules,p[50][50]; 3 bool visit[50][50]; 4 void search(int i,int j) 5 { 6 if(visit[i][j])//已经遍历过,不再遍历 7 return; 8 visit[i][j]=1;//标志已访问 9 modules++;//块数加一 10 if(!(p[i][j]&8))//判断有没有南墙 11 search(i+1,j);12 if(!(p[i][j]&4))//判断有没有东墙 13 ... 阅读全文

posted @ 2012-08-15 10:03 小花熊 阅读(314) 评论(0) 推荐(0) 编辑

poj1011 Sticks
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 bool anUsed[65]; 7 int L,N,stick[65]; 8 bool cmp(int a,int b) 9 {10 return a>b;11 }12 bool DFS(int nUnusedSticks,int nLeft)13 {14 int i,j,k;15 if(!(nUnusedSticks||nLe 阅读全文

posted @ 2012-08-14 21:10 小花熊 阅读(153) 评论(0) 推荐(0) 编辑

poj1161 Walls
摘要:1 #include<cstdio> 2 #include<iostream> 3 #define MAX 0xfffffff 4 using namespace std; 5 int m,l; 6 int Area[201][251],G[201][201],People[251],Dist[31]; 7 int Init()//初始化数据 8 { 9 int i,j,k,t;10 for(i=1;i<=l;++i)11 {12 scanf("%d",&t);13 People[t]=i;14 }15 for(i=1... 阅读全文

posted @ 2012-08-14 19:38 小花熊 阅读(310) 评论(0) 推荐(0) 编辑

hdu1272 小希的迷宫
摘要:1 #include<string.h> 2 #include<stdio.h> 3 int f[100010];//存放一个节点的父节点的编号 4 bool is[100010];//标志编号为I的房间是否存在 5 void exist(int x,int y)//判断x,y点是否已经存在 6 { 7 if(!is[x]){ 8 is[x]=1; 9 f[0]++;//统计房间个数 10 }11 if(!is[y]){12 is[y]=1;13 f[0]++;14 }15 ... 阅读全文

posted @ 2012-08-14 09:35 小花熊 阅读(263) 评论(0) 推荐(0) 编辑

nyoj49 开心的小明
摘要:1 #include<cstring> 2 #include<iostream> 3 using namespace std; 4 int main() 5 { 6 int i,T,n,m,v,w; 7 int f[30001]; 8 cin>>T; 9 while(T--){10 cin>>n>>m;11 memset(f,0,(n+1)*sizeof(int));12 while(m--){13 cin>>v>>w;14 for(w*=v,i=n;i>=v;i-... 阅读全文

posted @ 2012-08-13 23:20 小花熊 阅读(317) 评论(0) 推荐(0) 编辑

hdu1232 畅通工程
摘要:1 #include<stdio.h> 2 int bin[1002]; 3 int findx(int x) 4 { 5 int r=x; 6 while(bin[r]!=r) 7 r=bin[r]; 8 return r; 9 }10 void merge(int x,int y)11 {12 int fx,fy;13 fx=findx(x);14 fy=findx(y);15 if(fx!=fy)16 bin[fx]=fy;17 }18 int main()19 {20 int i,j,m,n,x,... 阅读全文

posted @ 2012-08-13 20:49 小花熊 阅读(149) 评论(0) 推荐(0) 编辑

hdu1874 畅通工程续
摘要:1 #include<stdio.h> 2 #define N 210 3 #define M 0xffffff 4 int D[N];//存放v0到其余节点的最短路径 5 int arc[N][N];//存放边的权值 6 int vexnum,arcnum;//村庄数及道路数 7 int ShortPath(int v0,int v1) 8 { 9 int v,w,k,min;10 int vis[N];//标志数组,记录最小路径节点 11 if(v0==v1) return 0;12 for(v=0;v<vexnum;v++){13 ... 阅读全文

posted @ 2012-08-13 16:44 小花熊 阅读(160) 评论(0) 推荐(0) 编辑

hdu1106 排序
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 int cmp(const void *a,const void *b) 5 { 6 return *(int *)a-*(int *)b; 7 } 8 int main() 9 {10 int i,j,len;11 char s[1001];12 int a[1000];13 while(~scanf("%s",s))14 {15 memset(a,0,sizeof(a));16 le... 阅读全文

posted @ 2012-08-13 15:31 小花熊 阅读(164) 评论(0) 推荐(0) 编辑

hdu2085 核反应堆
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int i,n; 5 __int64 high,low,k; 6 while(scanf("%d",&n),n+1) 7 { 8 for(high=1,low=i=0;i<n;++i) 9 {10 k=high;11 high=3*high+2*low;12 low=k+low;13 }14 printf("%I64d, %I64d\n",high,... 阅读全文

posted @ 2012-08-13 15:28 小花熊 阅读(154) 评论(0) 推荐(0) 编辑

hdu2094 产生冠军
摘要:1 #include<stdio.h> 2 #include<string.h> 3 struct node{ 4 char win[20],lost[20]; 5 int score; 6 }game[1000]; 7 int main() 8 { 9 int i,j,n,flag;10 while(scanf("%d",&n),n)11 {12 memset(game,0,sizeof(game));13 for(i=0;i<n;++i){14 scanf("%s%s",game[i].win... 阅读全文

posted @ 2012-08-13 15:13 小花熊 阅读(183) 评论(0) 推荐(0) 编辑

hdu1999 不可摸数
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int i,j,n,prime[1000]={1,1}; 5 for(i=2;i<1000;++i) 6 if(!prime[i]) 7 for(j=i+i;j<1000;j+=i) 8 prime[j]=1; 9 scanf("%d",&j);10 while(j--){11 scanf("%d",&n);12 if(!prime[--n]){13 put... 阅读全文

posted @ 2012-08-13 15:11 小花熊 阅读(211) 评论(0) 推荐(0) 编辑

hdu2574 Hdu Girls' Day
摘要:1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int T,i,n,no,cnt,mCnt; 6 char name[21],mName[21]; 7 scanf("%d",&T); 8 while(T--){ 9 mCnt=-1;10 *mName=0;11 scanf("%d",&n);12 while(n--){13 scanf("%s%d",name,&no);14 fo... 阅读全文

posted @ 2012-08-13 15:09 小花熊 阅读(214) 评论(0) 推荐(0) 编辑

nyoj119 士兵杀敌(三)
摘要:1 #include<iostream> 2 #include<cstdio> 3 #define N 100010 4 using namespace std; 5 struct node{ 6 int l,r; 7 int max,min; 8 }tree[3*N]; 9 int num[N];10 int Max,Min;11 void build(int l,int r,int i)12 { 13 tree[i].l=l;14 tree[i].r=r;15 if(l==r){16 tree[i].max=tree[i].m... 阅读全文

posted @ 2012-08-13 10:57 小花熊 阅读(291) 评论(0) 推荐(0) 编辑

nyoj123 士兵杀敌(四)
摘要:1 #include<stdio.h> 2 #define N 1000010 3 struct node{ 4 int l,r; 5 int inc; 6 }tree[3*N]; 7 inline void build(int l,int r,int i) 8 { 9 tree[i].l=l;10 tree[i].r=r;11 if(l<r){12 int mid=(l+r)>>1;13 build(l,mid,i<<1);14 build(mid+1,r,(i<<1)+1);15 }16 }1... 阅读全文

posted @ 2012-08-13 09:37 小花熊 阅读(354) 评论(0) 推荐(0) 编辑

poj3468 A Simple Problem with Integers
摘要:1 #include<stdio.h> 2 #define N 100010 3 struct node{ 4 int l,r; 5 __int64 inc,sum;//注意要定义为__int64型 6 }tree[3*N]; 7 int num[N]; 8 void build(int l,int r,int i)//建立线段树 9 {10 tree[i].l=l;11 tree[i].r=r;12 tree[i].inc=0;13 if(l==r){14 tree[i].sum=num[l];//叶子节点赋值 15 ... 阅读全文

posted @ 2012-08-10 20:41 小花熊 阅读(150) 评论(0) 推荐(0) 编辑

poj2182 Lost Cows
摘要:1 #include<stdio.h> 2 #define N 8010 3 struct node{ 4 int l,r; 5 int len;//len用来存放某一段数据的个数 6 }tree[N<<1]; 7 int s[N],result[N]; 8 void build(int l,int r,int i) 9 {10 tree[i].l=l;11 tree[i].r=r;12 tree[i].len=r-l+1; 13 if(l==r) return;14 int mid=(l+r)>>1;15 build(l,m... 阅读全文

posted @ 2012-08-10 15:04 小花熊 阅读(336) 评论(0) 推荐(0) 编辑

hdu1754 I Hate It
摘要:1 #include<cstdio> 2 #include<cmath> 3 #include<iostream> 4 #define MAX 200010 5 using namespace std; 6 struct node{ 7 int l,r; 8 int max; 9 }tree[3*MAX];//三倍就差不多了10 int s[MAX];11 void build(int l,int r,int i)//负责建树 12 {13 tree[i].l=l;14 tree[i].r=r;15 if(l==r){16 tree[i... 阅读全文

posted @ 2012-08-10 11:00 小花熊 阅读(162) 评论(0) 推荐(0) 编辑

hdu1251统计难题
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 struct node{ 6 int count; 7 node *next[26]; 8 node(){ //初始化数据 9 memset(next,NULL,sizeof(next));10 count=0;11 }12 };13 node *p,*root=new node();14 void insert(char *s)//插入新单词 15 {1... 阅读全文

posted @ 2012-08-09 17:27 小花熊 阅读(269) 评论(0) 推荐(0) 编辑

zoj1610 Count the Colors
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #define N 8001 4 int color[N],cnt[N];//这个cnt是用来记录颜色i出现的段数 ,注意cnt里的这个N真的需要好大,我以为就几百种呢,结果WA好多次 5 int main() 6 { 7 int i,j,a,b,c,max,n; 8 while(~scanf("%d",&n)){ 9 for(max=i=0;i<n;++i){10 scanf("%d%d%d",&a,&b,& 阅读全文

posted @ 2012-08-09 17:22 小花熊 阅读(575) 评论(0) 推荐(0) 编辑

nyoj144 小珂的苦恼
摘要:#include<stdio.h>inline int gcd(int a,int b){ return b?gcd(b,a%b):a;}int main(){ int T,a,b,k,n; scanf("%d",&T); while(T--) { scanf("%d%d%d",&a,&b,&n); k=gcd(a,b); if(n%k) puts("No"); else puts("Yes"); } return 0;}本题主要用到的是扩展欧几里德定理: 对于与不完全为 阅读全文

posted @ 2012-08-09 12:01 小花熊 阅读(226) 评论(1) 推荐(1) 编辑

nyoj163 Phone List
摘要:1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 struct node{ 6 node *next[10]; 7 int end; 8 node(){ //构造函数,方便初始化数据 9 memset(next,NULL,sizeof(next));10 end=0; //end=0表示一般节点,end=1标志一个电话号的结束 11 }12 };13 node *root;14 bool insert(... 阅读全文

posted @ 2012-08-09 01:45 小花熊 阅读(247) 评论(0) 推荐(0) 编辑

nyoj290 动物统计加强版
摘要:1 #include<cstring> 2 #include<cstdio> 3 #include<iostream> 4 using namespace std; 5 struct node{ 6 node *next[26]; 7 int count; 8 node(){ //构造函数,初始化数据 9 memset(next,0,sizeof(next));10 count=0;11 }12 };13 int maxi; //用来存放最大出现次数 14 char maxs[11];//存放出现次数最多的字符串... 阅读全文

posted @ 2012-08-08 21:10 小花熊 阅读(240) 评论(0) 推荐(0) 编辑

nyoj93 汉诺塔(三)
摘要:1 #include<stack> 2 #include<iostream> 3 using namespace std; 4 int main() 5 { 6 int i,t,N,a,b,m,n; 7 stack<int> s[4]; //定义一个数组栈 8 cin>>N; 9 while(N--)10 {11 cin>>m>>n;12 for(i=1;i<4;i++)13 while(!s[i].empty()) s[i].pop(); //清空栈 14 for(i=m;i... 阅读全文

posted @ 2012-08-08 17:01 小花熊 阅读(219) 评论(0) 推荐(0) 编辑

nyoj517 最小公倍数
摘要:1 //我的代码: 2 #include<stdio.h> 3 #include<string.h> 4 #define N 50 5 int len,a[N]={1}; 6 char tab[100][45]={0,1}; 7 inline int gcd(int a,int b) 8 { 9 return b==0?a:gcd(b,a%b);10 }11 int mod(int t) //求余12 {13 int i,k;14 for(k=0,i=len-1;i>=0;--i){15 k=(k*10+a[i])%t;16 }17 ... 阅读全文

posted @ 2012-08-08 11:59 小花熊 阅读(366) 评论(0) 推荐(0) 编辑

poj1686 Lazy Math Instructor
摘要:1 #include<map> 2 #include<stack> 3 #include<cctype> 4 #include<iostream> 5 using namespace std; 6 map<char,int> m; //从字符映射到数字 7 string s1,s2,r1,r2; 8 string transform(string s)//把表达式转化为后缀表达式方便计算 9 {10 int i,j,len;11 char c[81];12 stack<char> exp; //定义一个字符栈,存放运算符 阅读全文

posted @ 2012-08-07 21:32 小花熊 阅读(612) 评论(1) 推荐(1) 编辑

poj1028 Web Navigation
摘要:Accepted360K16MSG++700B 1 #include<stdio.h> 2 #include<string.h> 3 char fs[100][71],bs[100][71]; 4 int ftop,btop; 5 int main() 6 { 7 char a[8],cur[71]; 8 strcpy(cur,"http://www.acm.org/"); 9 while(scanf("%s",a),strcmp(a,"QUIT")){10 if(!strcmp(a,"VISIT&q 阅读全文

posted @ 2012-08-07 16:23 小花熊 阅读(194) 评论(0) 推荐(0) 编辑

poj1250 Tanning Salon
摘要:1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 char c,p[26]; 6 int n,curnum,leave; 7 while(scanf("%d%*c",&n),n) 8 { 9 curnum=leave=0;10 memset(p,0,sizeof(p));11 for(c=getchar();c!='\n';c=getchar()){12 if(p[c-'A']==1){13 ... 阅读全文

posted @ 2012-08-07 11:25 小花熊 阅读(215) 评论(0) 推荐(0) 编辑

poj2082 Terrible Sets
摘要:1 #include<stdio.h> 2 struct Node{ //定义堆栈 3 int w,h; //w为目前为止整个区域的宽度,h为当前矩形的高度 4 }stack[50001]; 5 int main() 6 { 7 int i,n,top,totalw; //top为栈顶指针,totalw为总的宽度 8 int curw,curh,maxsize; //curw,curh为新矩形高度,宽度。maxsize为当前最大矩形面积 9 while(scanf("%d",&n),n+1)10 {11 for(totalw=... 阅读全文

posted @ 2012-08-07 10:11 小花熊 阅读(414) 评论(0) 推荐(0) 编辑

poj2359 Questions
摘要:1 #include<stdio.h> 2 #include<string.h> 3 char s[30001],str[30001]; 4 int main() 5 { 6 int i,k,len; 7 while(gets(str)) 8 strcat(s,str); 9 len=strlen(s);10 for(k=0,i=2;i<=len;++i)11 k=(k+1999)%i;12 if(s[k]=='?') printf("Yes\n");13 else if(s[k]==' ') printf(&q 阅读全文

posted @ 2012-08-06 18:34 小花熊 阅读(185) 评论(0) 推荐(0) 编辑

poj3250 Bad Hair Day
摘要:1 //超时代码 2 #include<stdio.h> 3 unsigned ans; 4 int main() 5 { 6 int i,j,n,Q[80000]; 7 scanf("%d",&n); 8 for(i=0;i<n;++i) 9 scanf("%d",&Q[i]);10 for(i=n-1;i>=0;--i){ //从后往前读 11 for(j=i+1;j<n&&Q[i]>Q[j];++j); //从i处往后查找,直到碰到大于等于它的数为止 12 ans+=j-i-1; 阅读全文

posted @ 2012-08-06 18:00 小花熊 阅读(265) 评论(1) 推荐(1) 编辑

hdu1053 Entropy
摘要:1 #include<iostream> 2 #include<iomanip> 3 #define N 27 4 using namespace std; 5 int cmp(const void *a,const void *b) 6 { 7 return *(int *)b-*(int *)a; //从大到小排序,方便对最小次小值的 操作 8 } 9 int main()10 {11 string s;12 int num[27],a[27];13 int i,j,wpl,len;14 while(cin>>s,s!="END"){ 阅读全文

posted @ 2012-08-06 09:18 小花熊 阅读(577) 评论(0) 推荐(0) 编辑

poj1936 All in All
摘要:1 #include<stdio.h> 2 char str[100001],sub[100001]; 3 int main() 4 { 5 int i,k; 6 while(~scanf("%s%s",sub,str)) 7 { 8 for(k=i=0;str[i];i++) 9 if(str[i]==sub[k]&&sub[k])10 k++;11 if(sub[k]) printf("No\n");12 else printf("Yes\n");13 ... 阅读全文

posted @ 2012-08-03 23:50 小花熊 阅读(151) 评论(0) 推荐(0) 编辑

poj1047 Round and Round We Go
摘要:1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 char s[65],b[65],str[60][65]; 6 int i,k,t,c,len; 7 bool flag; 8 while(~scanf("%s",s)){ 9 len=strlen(s);10 for(i=0;i<len;++i){11 strcpy(str[i],s+i);12 strncat(str[i],s,i);13 }1... 阅读全文

posted @ 2012-08-03 23:02 小花熊 阅读(159) 评论(0) 推荐(0) 编辑

hdu2036 改革春风吹满地
摘要:1 #include<math.h> 2 #include<stdio.h> 3 int main() 4 { 5 int i,n,a[110][2]; 6 double s; 7 while(scanf("%d",&n),n) 8 { 9 for(s=i=0;i<n;i++)10 scanf("%d%d",&a[i][0],&a[i][1]);11 for(i=2;i<n;i++)12 s+=(a[i][1]-a[i-1][1])*(a[0][0]-a[i][0]) //注意是有向面积,因为. 阅读全文

posted @ 2012-08-03 18:42 小花熊 阅读(188) 评论(0) 推荐(0) 编辑

poj1298 The Hardest Problem Ever
摘要:1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 int main() 5 { 6 char *p,s[201]; 7 while(cin.getline(s,100),strcmp(s,"ENDOFINPUT")) 8 { 9 if(!strcmp(s,"START")) continue;10 else if(!strcmp(s,"END")) continue;11 else{12 for(p=s;*p;p++... 阅读全文

posted @ 2012-08-03 15:49 小花熊 阅读(165) 评论(0) 推荐(0) 编辑

nyoj305 表达式求值
摘要:1 #include<stdio.h> 2 char s[301],cstack[120]; 3 int dstack[80]; 4 int i,ctop,dtop; 5 int Operate(int a,char theta,int b) 6 { 7 switch(theta){ 8 case 'd': return a+b; 9 case 'n': return a>b?b:a;10 case 'x': return a>b?a:b;11 }12 }13 int EvaluateExpression()14 {15 阅读全文

posted @ 2012-08-03 12:41 小花熊 阅读(227) 评论(0) 推荐(0) 编辑

poj2255 Tree Recovery
摘要:1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 using namespace std; 5 struct Node 6 { 7 char data; 8 Node *lchild; 9 Node *rchild;10 };11 Node *CreatTree(string pre,string in)12 {13 Node *root=NULL;14 if(pre.length()>0)15 {16 root=new Node;17 ... 阅读全文

posted @ 2012-08-03 09:35 小花熊 阅读(157) 评论(0) 推荐(0) 编辑

poj1363 Rails
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int Sq[1000],a[1000]; 5 int i,k,n,head; 6 while(~scanf("%d",&n),n){ 7 while(scanf("%d",&a[0]),a[0]){ 8 for(head=0,i=1;i<n;++i) 9 scanf("%d",&a[i]);10 for(i=1,k=0;k<n;++k){11 while(i<a[... 阅读全文

posted @ 2012-08-02 16:47 小花熊 阅读(226) 评论(0) 推荐(0) 编辑

nyoj128 前缀式计算
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #define N 1010 5 char s[N]; 6 //数字栈的操作 7 typedef struct 8 { 9 float *base; 10 float *top; 11 }SqStack; 12 int InitStack(SqStack &S) 13 { 14 S.base=(float *)malloc(N/2*sizeof(float)); 15 S.top=S.base; 16 return 1; 1 阅读全文

posted @ 2012-08-02 10:14 小花熊 阅读(200) 评论(0) 推荐(0) 编辑

nyoj467 中缀式变后缀式
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define N 1010 4 //字符栈的操作 5 typedef struct 6 { 7 char *base; 8 char *top; 9 }SqStack; 10 int InitStack(SqStack &S) 11 { 12 S.base=(char *)malloc(N*sizeof(char)); 13 if(!S.base) exit(1); 14 S.top=S.base; 15 return 1; 16 } 17 int StackE... 阅读全文

posted @ 2012-08-02 08:39 小花熊 阅读(319) 评论(0) 推荐(0) 编辑

nyoj267 郁闷的C小加(二)
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define N 1010 4 char s[N]; 5 int i; 6 //字符栈的操作 7 typedef struct 8 { 9 char *base; 10 char *top; 11 }SqStack1; 12 int InitStack1(SqStack1 &S) 13 { 14 S.base=(char *)malloc(N*sizeof(char)); 15 if(!S.base) exit(1); 16 S.top=S.base; 17 ... 阅读全文

posted @ 2012-08-02 08:37 小花熊 阅读(264) 评论(0) 推荐(0) 编辑

nyoj35 表达式求值
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define N 1010 4 char s[N]; 5 //字符栈的操作 6 typedef struct 7 { 8 char *base; 9 char *top; 10 }SqStack1; 11 int InitStack1(SqStack1 &S) 12 { 13 S.base=(char *)malloc(N*sizeof(char)); 14 if(!S.base) exit(1); 15 S.top=S.base; 16 return 1; ... 阅读全文

posted @ 2012-08-02 08:36 小花熊 阅读(351) 评论(0) 推荐(0) 编辑

nyoj257 郁闷的C小加(一)
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define N 1010 4 //字符栈的操作 5 typedef struct 6 { 7 char *base; 8 char *top; 9 }SqStack; 10 int InitStack(SqStack &S) 11 { 12 S.base=(char *)malloc(N*sizeof(char)); 13 if(!S.base) exit(1); 14 S.top=S.base; 15 return 1; 16 } 17 int StackE... 阅读全文

posted @ 2012-08-02 08:36 小花熊 阅读(255) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示