ZOJ-#3465 The Hive(字符串模拟)
2014-09-16 20:35
323 查看
题目大意:给出蜂箱的布局,现在蜜蜂开始按照不同列,从下向上的顺序开始,当上下相邻的两个相同则合并为一个糖果,每一列满了之后,将不会发生任何变化,问有多个糖果产生,以及每一次测试后的蜂箱的布局。
解题思路:题目描述的不是很清楚,这是一个体力的模拟,直接模拟就可以搞定,但需要很多体力去做,细心一点就可以了。这里就不赘述了,详见code。
题目来源:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3465
code:
解题思路:题目描述的不是很清楚,这是一个体力的模拟,直接模拟就可以搞定,但需要很多体力去做,细心一点就可以了。这里就不赘述了,详见code。
题目来源:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3465
code:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int MAXN = 15; int n,ans; char p,q; int a,b,c,d,e,f,g,h,i; char A[MAXN],B[MAXN],C[MAXN],D[MAXN],E[MAXN],F[MAXN],G[MAXN],H[MAXN],I[MAXN]; char hive[40][30]; char str[40][30]={ " _", " _/ \\_", " _/ \\_/ \\_", " _/ \\_/ \\_/ \\_", " _/ \\_/ \\_/ \\_/ \\_", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", "/ \\_/ \\_/ \\_/ \\_/ \\", "\\_/ \\_/ \\_/ \\_/ \\_/", " \\_/ \\_/ \\_/ \\_/", " \\_/ \\_/ \\_/", " \\_/ \\_/", " \\_/" }; void init(){ ans=0; a=b=c=d=e=f=g=h=i=0; memcpy(hive,str,sizeof(str)); //记得初始化,这里WA了好多次 for(int j=0;j<10;j++) memset(A+j,0,sizeof(A+j)); } void prin(){ //更改对应位置的值 if(a!=0) for(int j=a;j>0;j--) hive[19-2*j][1]=A[j]; if(b!=0) for(int j=b;j>0;j--) hive[20-2*j][3]=B[j]; if(c!=0) for(int j=c;j>0;j--) hive[21-2*j][5]=C[j]; if(d!=0) for(int j=d;j>0;j--) hive[22-2*j][7]=D[j]; if(e!=0) for(int j=e;j>0;j--) hive[23-2*j][9]=E[j]; if(f!=0) for(int j=f;j>0;j--) hive[22-2*j][11]=F[j]; if(g!=0) for(int j=g;j>0;j--) hive[21-2*j][13]=G[j]; if(h!=0) for(int j=h;j>0;j--) hive[20-2*j][15]=H[j]; if(i!=0) for(int j=i;j>0;j--) hive[19-2*j][17]=I[j]; for(int j=0;j<23;j++){ printf("%s\n",hive[j]); } } int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d",&n)){ getchar(); init(); for(int j=0;j<n;j++){ scanf("%c%c",&p,&q); getchar(); if(p=='A' && a<7){ //对应列的计数 A[++a]=q; if(A[a]==A[a-1] && a!=1){ans++;a-=2;continue;} } else if(p=='B' && b<8){ B[++b]=q; if(B[b]==B[b-1] && b!=1){ans++;b-=2;continue;} } else if(p=='C' && c<9){ C[++c]=q; if(C[c]==C[c-1] && c!=1){ans++;c-=2;continue;} } else if(p=='D' && d<10){ D[++d]=q; if(D[d]==D[d-1] && d!=1){ans++;d-=2;continue;} } else if(p=='E' && e<11){ E[++e]=q; if(E[e]==E[e-1] && e!=1){ans++;e-=2;continue;} } else if(p=='F' && f<10){ F[++f]=q; if(F[f]==F[f-1] && f!=1){ans++;f-=2;continue;} } else if(p=='G' && g<9){ G[++g]=q; if(G[g]==G[g-1] && g!=1){ans++;g-=2;continue;} } else if(p=='H' && h<8){ H[++h]=q; if(H[h]==H[h-1] && h!=1){ans++;h-=2;continue;} } else if(p=='I' && i<7){ I[++i]=q; if(I[i]==I[i-1] && b!=1){ans++;i-=2;continue;} } } printf("The number of candy is %d.\n",ans); prin(); } return 0; }
相关文章推荐
- ZOJ 3465 The Hive 暴力模拟
- zoj 3466 The Hive II
- ZOJ 2392 The Counting Problem(模拟)
- zoj 3879 Capture the Flag(长模拟)
- ZOJ 3780 Paint the Grid Again 模拟
- ZOJ 3674 Search in the Wiki 【C++STL大法尽情地模拟】
- zoj 1016 字符串模拟 ~小狼回来做题了!!
- ZOJ-3879-Capture the Flag【模拟】【12th浙江省赛】
- 【模拟】 ZOJ 3879 Capture the Flag
- 【ZOJ 3780】Paint the Grid Again —— 模拟拓扑排序
- ZOJ 3826 Hierarchical Notation(模拟-字符串处理)
- ZOJ 3466 The Hive II 解题报告(插头DP)
- hdu 1800 Flying to the Mars(简单模拟,string,字符串)
- 字符串的处理(模拟) ZOJ Problem Set - 1099 HTML
- ZOJ 3879 Capture the Flag (浙江省省赛K题+模拟)
- ZOJ 3466 The Hive II 插头DP
- ZOJ 3466 The Hive II(插头DP)
- ZOJ 3780 Paint the Grid Again (模拟)
- ZOJ 3826 Hierarchical Notation(2014 牡丹江 H,字符串模拟)
- zoj 3879 Capture the Flag(模拟 数学)