NC216202. JiubeiAndHearthstoneBattlegrounds
描述
输入描述
输入的第一行包含两个非负整数 和 表示 jiubei 和他的对手分别拥有几个随从。
接下来的 行按照从左至右的顺序给出了jiubei 拥有的随从的信息。每一行包含一个随从的信息,表示方式如下:
Taunt Reborn... 是这个随从的攻击力, 是这个随从的生命值,随后是这个随从所具有的关键字。
接下来的 行按照从左至右的顺序给出了 jiubei 的对手拥有的随从的信息,表示方式同上。
输入保证 ,并且对于一个随从不会出现多个同样的关键字。
如果你依旧不能理解题目内容,可以参考输入样例。
输出描述
你需要输出战斗结束时战场上的随从信息。
第一行是场上所剩余的随从数量。
接下来按照从左到右的顺序,每行输出一个随从的攻击力和生命值,格式为 。
示例1
输入:
1 2 2/5 1/1 Reborn Divine Shield 2/2 Poisonous Taunt DeathRattle(1,1,2) Reborn
输出:
4 1/1 2/1 1/1 1/1
C(clang11) 解法, 执行用时: 2ms, 内存消耗: 504K, 提交时间: 2020-12-26 23:39:20
#include <stdio.h> #include <string.h> int taunt_test(int); int first_test(int); void read(); void battle(); int hand = 0, cnt[2], winner = -1; struct dt { long long int harm, health, taunt, divine_shield, divine_shield_backup, reborn, poisonous, death_rattle[3]; } d[2][1200], dr; void read() { char ch, s[50]; memset(dr.death_rattle, 0, sizeof(dr.death_rattle)); dr.divine_shield = dr.divine_shield_backup = dr.poisonous = dr.reborn = dr.taunt = 0; scanf("%lld/%lld", &dr.harm, &dr.health); while (1) { ch = getchar(); if (ch == '\n') return; else { scanf("%s", s); if (strcmp(s, "Taunt") == 0) dr.taunt = 1; else if (strcmp(s, "Divine") == 0) { dr.divine_shield_backup = dr.divine_shield = 1; scanf("%s", s); } else if (strcmp(s, "Reborn") == 0) dr.reborn = 1; else if (strcmp(s, "Poisonous") == 0) dr.poisonous = 1; else { sscanf(s, "DeathRattle(%lld,%lld,%lld)", &dr.death_rattle[0], &dr.death_rattle[1], &dr.death_rattle[2]); } } } } void battle() { int first_taust = taunt_test(!hand), target, attacker, i; target = first_test(!hand); attacker = first_test(hand); if (target == -1) { winner = hand; return; } if (attacker == -1) { winner = !hand; return; } if (first_taust != -1) target = first_taust; if (d[!hand][target].divine_shield) d[!hand][target].divine_shield = 0; else { d[!hand][target].health -= d[hand][attacker].harm; if (d[hand][attacker].poisonous) d[!hand][target].health = 0; } if (d[hand][attacker].divine_shield) d[hand][attacker].divine_shield = 0; else { d[hand][attacker].health -= d[!hand][target].harm; if (d[!hand][target].poisonous) d[hand][attacker].health = 0; } if (d[!hand][target].health <= 0) { if (d[!hand][target].death_rattle[2]) { for (i = 0; i < d[!hand][target].death_rattle[2]; ++i) { d[!hand][cnt[!hand]].harm = d[!hand][target].death_rattle[0]; d[!hand][cnt[!hand]].health = d[!hand][target].death_rattle[1]; ++cnt[!hand]; } } if (d[!hand][target].reborn) { d[!hand][target].health = 1; d[!hand][target].reborn = 0; d[!hand][target].divine_shield = d[!hand][target].divine_shield_backup; } } if (d[hand][attacker].health <= 0) { if (d[hand][attacker].death_rattle[2]) { for (i = 0; i < d[hand][attacker].death_rattle[2]; ++i) { d[hand][cnt[hand]].harm = d[hand][attacker].death_rattle[0]; d[hand][cnt[hand]].health = d[hand][attacker].death_rattle[1]; ++cnt[hand]; } } if (d[hand][attacker].reborn) { d[hand][attacker].health = 1; d[hand][attacker].reborn = 0; d[hand][attacker].divine_shield = d[hand][attacker].divine_shield_backup; } } hand = !hand; } int taunt_test(int p) { int i; for (i = 0; i < cnt[!hand]; ++i) { if (d[p][i].health <= 0) continue; if (d[p][i].taunt) return i; } return -1; } int first_test(int p) { int i; for (i = 0; i < cnt[p]; ++i) { if (d[p][i].health > 0) return i; } return -1; } main() { int n, m, i, left; memset(d, 0, sizeof(d)); scanf("%d%d", &n, &m); for (i = 0; i < n; ++i) { read(); d[0][i] = dr; } for (i = 0; i < m; ++i) { read(); d[1][i] = dr; } cnt[0] = n; cnt[1] = m; while (winner == -1) battle(); left = 0; for (i = 0; i < cnt[winner]; ++i) if (d[winner][i].health > 0) ++left; printf("%d\n", left); for (i = 0; i < cnt[winner]; ++i) if (d[winner][i].health > 0) printf("%d/%d\n", d[winner][i].harm, d[winner][i].health); }
C++(clang++11) 解法, 执行用时: 6ms, 内存消耗: 6652K, 提交时间: 2020-12-26 18:07:32
#include <bits/stdc++.h> #define pb push_back #define F(i,j,k) for(int i=j;i<=k;i++) using namespace std; const int N=100010; int n,m; bool gameOver; vector<pair<int,int>> ans; struct servant{ int x,y,sa=0,sb=0,sc=0; bool tT=0,tDS=0,tR=0,tP=0,tDR=0; bool T=0,DS=0,R=0,P=0,DR=0; void read(){ string s; cin>>s; x=atoi(s.substr(0,s.find("/")).c_str()); y=atoi(s.substr(s.find("/")+1).c_str()); getline(cin,s); stringstream ss; ss<<s; while(ss>>s){ if(s=="Reborn")tR=R=1; if(s=="Divine")ss>>s,tDS=DS=1; if(s=="Poisonous")tP=P=1; if(s=="Taunt")tT=T=1; if(s.find("(")!=s.npos){ int l,m=0,r,a,b,c; for(int i=0;i<s.size();i++){ if(s[i]=='(')l=i; if(!m&&s[i]==',')m=i; if(i!=m&&s[i]==',')r=i; } sa=atoi(s.substr(l+1).c_str()); sb=atoi(s.substr(m+1).c_str()); sc=atoi(s.substr(r+1).c_str()); tDR=DR=1; } } } }a[N],b[N]; void death(servant a[],int id,int f){ if(a[id].tDR){ servant t; t.x=a[id].sa,t.y=a[id].sb; F(i,1,a[id].sc)a[f?++n:++m]=t; a[id].tDR=0; } if(a[id].tR){ a[id].y=1,a[id].tDS=a[id].DS; a[id].tDR=a[id].DR; a[id].tR=0; } } void battle(){ int ia=0,ib=0; F(i,1,n)if(a[i].y){ia=i;break;} F(i,1,m)if(b[i].tT&&b[i].y){ib=i;break;} if(!ib)F(i,1,m)if(b[i].y){ib=i;break;} if(!ia||!ib){gameOver=1;return;} if(b[ib].tDS)b[ib].tDS=0; else{ b[ib].y=max(b[ib].y-(a[ia].P?1000:a[ia].x),0); if(!b[ib].y)death(b,ib,0); } if(a[ia].tDS)a[ia].tDS=0; else{ a[ia].y=max(a[ia].y-(b[ib].P?1000:b[ib].x),0); if(!a[ia].y)death(a,ia,1); } ia=0,ib=0; F(i,1,m)if(b[i].y){ib=i;break;} F(i,1,n)if(a[i].tT&&a[i].y){ia=i;break;} if(!ia)F(i,1,n)if(a[i].y){ia=i;break;} if(!ia||!ib){gameOver=1;return;} if(a[ia].tDS)a[ia].tDS=0; else{ a[ia].y=max(a[ia].y-(b[ib].P?1000:b[ib].x),0); if(!a[ia].y)death(a,ia,1); } if(b[ib].tDS)b[ib].tDS=0; else{ b[ib].y=max(b[ib].y-(a[ia].P?1000:a[ia].x),0); if(!b[ib].y)death(b,ib,0); } } int main(){ cin>>n>>m; F(i,1,n)a[i].read(); F(i,1,m)b[i].read(); while(!gameOver)battle(); F(i,1,n)if(a[i].y)ans.pb({a[i].x,a[i].y}); F(i,1,m)if(b[i].y)ans.pb({b[i].x,b[i].y}); cout<<ans.size()<<"\n"; for(auto i:ans)cout<<i.first<<"/"<<i.second<<"\n"; }