ZOJ-#3465 The Hive(字符串模拟)
来源:互联网 发布:淘宝嘉年华报名要求 编辑:程序博客网 时间:2024/05/16 07:30
题目大意:给出蜂箱的布局,现在蜜蜂开始按照不同列,从下向上的顺序开始,当上下相邻的两个相同则合并为一个糖果,每一列满了之后,将不会发生任何变化,问有多个糖果产生,以及每一次测试后的蜂箱的布局。
解题思路:题目描述的不是很清楚,这是一个体力的模拟,直接模拟就可以搞定,但需要很多体力去做,细心一点就可以了。这里就不赘述了,详见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;}
0 0
- ZOJ-#3465 The Hive(字符串模拟)
- ZOJ 3465 The Hive 暴力模拟
- ZOJ 3879 Capture the Flag(模拟)
- zoj-3826(字符串模拟)
- zoj 3466 The Hive II
- ZOJ 3466 The Hive II
- ZOJ 3466 The Hive II 解题报告(插头DP)
- zoj Defuse the Bomb (模拟)
- ZOJ 3826 hash+字符串模拟
- zoj 2971 Give Me the Number (模拟)
- zoj 3879 Capture the Flag(长模拟)
- zoj 3879 Capture the Flag(模拟 数学)
- ZOJ 1610 Count the Colors(数组模拟)
- ZOJ 2971 Give Me the Number(模拟)
- ZOJ 3432 Find the Lost Sock(模拟)
- ZOJ 3466 The Hive II 插头DP
- zoj 3466 The Hive II(插头dp)
- 字符串的处理(模拟) ZOJ Problem Set - 1099 HTML
- install oracle java in ubuntu 12.04
- 百度地图初步Hello BaiduMap——(参考Baidu官网)
- IAR中代码在flash和ram中调试流程
- RHCE6 Preperation (2) - yum source and auto mount
- ios单例
- ZOJ-#3465 The Hive(字符串模拟)
- strcpy源码分析
- 暑期开发过程中的一些经验记录
- 如果刚装好的ORACLE,却无法访问数据库,则把LINSTENER删除试试
- 【POJ3208】传说中POJ最难的数位DP?(正解AC自动机,二解数位DP,吾异与之)
- luaAPI解析
- Internal Patent Idea Candidates
- CF 题目集锦 PART 7 #264 div 2 E
- 根据MySQL表数据导出INSERT INTO语句的方法