CCF炉石传说
来源:互联网 发布:linux网关配置命令 编辑:程序博客网 时间:2024/06/09 22:55
心得:
写这种题关键就是操作分开写,写完一个测试一个。要不然代码多,调试困难,思路乱,导致做错。
代码:
#include <cstdio>#include <iostream>#include <string>#include <cstring>using namespace std;struct sss{ int health; int attack;};int f,fff;struct hero{ int cnt; struct sss sc[10];}h[2];int is_c(string t){ if(t == "summon") return 1; else if(t == "attack") return 2; else if(t == "end") return 3; else return 4;}void _init(){ h[0].cnt = h[1].cnt = 0; memset(h[0].sc,0,sizeof h[0].sc); memset(h[1].sc,0,sizeof h[1].sc); h[0].sc[0].health = h[1].sc[0].health = 30;}void _summon(int pos,int attack,int health){ h[f % 2].cnt++; for(int i = h[f % 2].cnt;i > pos;--i) { h[f % 2].sc[i] = h[f % 2].sc[i - 1]; } h[f % 2].sc[pos].attack = attack; h[f % 2].sc[pos].health = health;}void _delete(int pos,int ff){ int a = (f + ff) % 2; for(int i = pos;i <= h[a].cnt;++i) h[a].sc[i] = h[a].sc[i + 1]; h[a].cnt--;}void _attack(int pos_a,int pos_d){ int a = f % 2; int b = (f + 1) % 2; h[a].sc[pos_a].health -= h[b].sc[pos_d].attack; h[b].sc[pos_d].health -= h[a].sc[pos_a].attack; if(h[a].sc[pos_a].health <= 0) _delete(pos_a,0); if(h[b].sc[pos_d].health <= 0 && pos_d) _delete(pos_d,1); if(h[b].sc[pos_d].health <= 0 && !pos_d) fff = 1;}void _print(){ if(h[0].sc[0].health > 0 && h[1].sc[0].health > 0) printf("0\n"); else if(h[0].sc[0].health > 0 && h[1].sc[0].health <= 0) printf("1\n"); else printf("-1\n"); printf("%d\n%d",h[0].sc[0].health,h[0].cnt); for(int i = 1;i <= h[0].cnt;++i) printf(" %d",h[0].sc[i].health); printf("\n%d\n%d",h[1].sc[0].health,h[1].cnt); for(int i = 1;i <= h[1].cnt;++i) printf(" %d",h[1].sc[i].health); printf("\n");}int main(){ int n; int pos,attack,health; int pos_a,pos_d; string t; f = fff = 0; while(~scanf("%d",&n)) { _init(); while(n--) { cin >> t; if(is_c(t) == 1) //summon { cin >> pos >> attack >> health; if(!fff) _summon(pos,attack,health); } else if(is_c(t) == 2) //attack { cin >> pos_a >> pos_d; if(!fff) _attack(pos_a,pos_d); } else if(is_c(t) == 3) // end { f++; } } _print(); } return 0;}
0 0
- CCF 炉石传说
- CCF炉石传说
- ccf 炉石传说
- CCF-炉石传说
- CCF-炉石传说
- CCF炉石传说
- CCF炉石传说
- CCF-炉石传说
- CCF 炉石传说
- ccf炉石传说
- ccf 炉石传说
- ccf 炉石传说
- CCF 炉石传说 <模拟>
- 炉石传说-CCF往届题
- ccf试题 炉石传说
- ccf 炉石传说 模拟
- CCF 201609-3 炉石传说
- CCF 201612-3 炉石传说
- Event对象(事件对象)的常用属性、方法和事件流
- 划分数, n的m划分 [dp计数] 《挑战程序设计竞赛》2.3
- Mat和iplimage类型转换
- 【图像特征提取2】局部二值模式LBP----从原理到实践
- 指向函数的指针
- CCF炉石传说
- git github入门教程
- R语言
- 网上下载项目导入studio简单方法减少报错
- 一篇很全面的freemarker教程
- 小兔棋盘
- Android布局优化之merge(二)
- .NET入行之工作前
- 阅读 ANDROID 源码的一些姿势