【CCF 炉石传说 模拟题】
2016-11-30 16:39
369 查看
按照题目说的进行模拟操作就好了,注意维护slave队列
刚开始的时候wa了,因为在对死亡者进行pop的时候,可能死亡的是英雄,那等到显示slave的时候就会越界
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
class slave
{
public:
int h, a;
slave(){}
slave(int hh, int aa){h=hh,a=aa;}
};
class person
{
public:
int num;
slave* que[10];
person(){num = 0;que[0]=new slave(30,0);}
void push(int pos,int at, int hl)
{
if(pos<=num)
{
for(int i=num+1;i>pos;i--) que[i]=que[i-1];
}
num++;
que[pos]=new slave(hl, at);
}
void pop(int pos)
{
for(int i=pos;i<num;i++) que[i]=que[i+1];
que[num--]=NULL;
}
void out()
{
for(int i=1;i<=num;i++) cout<<que[i]->h<<" "<<que[i]->a<<endl;
}
};
int main()
{
int n;
while(cin>>n)
{
int now = 0;
person s[2];
while(n--)
{
string op;
cin>>op;
int a,b,c;
if(op=="summon")
{
cin>>a>>b>>c;
s[now].push(a,b,c);
}
else if(op=="attack")
{
cin>>a>>b; //at,def
slave* me, *you;
for(int i=0;i<=s[now].num;i++) if(i==a) me=s[now].que[i];
for(int i=0;i<=s[!now].num;i++) if(i==b) you = s[!now].que[i];
me->h-=you->a;
you->h-=me->a;
if(me->h<=0 && a) s[now].pop(a);
if(you->h<=0 && b) s[!now].pop(b);
}
else if(op=="end")
{
now=!now;
}
}
if(s[0].que[0]->h>0&&s[1].que[0]->h>0) cout<<0<<endl;
else if(s[0].que[0]->h<=0) cout<<-1<<endl;
else if(s[1].que[0]->h<=0) cout<<1<<endl;
for(int i=0;i<2;i++)
{
cout<<s[i].que[0]->h<<endl;
cout<<s[i].num<<" ";
for(int j=1;j<=s[i].num;j++) cout<<s[i].que[j]->h<<" ";
cout<<endl;
}
}
return 0;
}
刚开始的时候wa了,因为在对死亡者进行pop的时候,可能死亡的是英雄,那等到显示slave的时候就会越界
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
class slave
{
public:
int h, a;
slave(){}
slave(int hh, int aa){h=hh,a=aa;}
};
class person
{
public:
int num;
slave* que[10];
person(){num = 0;que[0]=new slave(30,0);}
void push(int pos,int at, int hl)
{
if(pos<=num)
{
for(int i=num+1;i>pos;i--) que[i]=que[i-1];
}
num++;
que[pos]=new slave(hl, at);
}
void pop(int pos)
{
for(int i=pos;i<num;i++) que[i]=que[i+1];
que[num--]=NULL;
}
void out()
{
for(int i=1;i<=num;i++) cout<<que[i]->h<<" "<<que[i]->a<<endl;
}
};
int main()
{
int n;
while(cin>>n)
{
int now = 0;
person s[2];
while(n--)
{
string op;
cin>>op;
int a,b,c;
if(op=="summon")
{
cin>>a>>b>>c;
s[now].push(a,b,c);
}
else if(op=="attack")
{
cin>>a>>b; //at,def
slave* me, *you;
for(int i=0;i<=s[now].num;i++) if(i==a) me=s[now].que[i];
for(int i=0;i<=s[!now].num;i++) if(i==b) you = s[!now].que[i];
me->h-=you->a;
you->h-=me->a;
if(me->h<=0 && a) s[now].pop(a);
if(you->h<=0 && b) s[!now].pop(b);
}
else if(op=="end")
{
now=!now;
}
}
if(s[0].que[0]->h>0&&s[1].que[0]->h>0) cout<<0<<endl;
else if(s[0].que[0]->h<=0) cout<<-1<<endl;
else if(s[1].que[0]->h<=0) cout<<1<<endl;
for(int i=0;i<2;i++)
{
cout<<s[i].que[0]->h<<endl;
cout<<s[i].num<<" ";
for(int j=1;j<=s[i].num;j++) cout<<s[i].que[j]->h<<" ";
cout<<endl;
}
}
return 0;
}
相关文章推荐
- [CCFwithAxin]201609-3炉石传说(模拟题)
- 4000 CCF-炉石传说
- CCF 201609-3 炉石传说
- csp ccf 201609-3 第三题炉石传说java 100
- CCF简单模拟题一水
- I'm stuck! ccf模拟题。
- CCF炉石传说
- CCF模拟题--ISBN号码
- CCF模拟题部分题目解题思路与AC代码
- ccf炉石传说
- CCF 模拟题 有趣的数 (数位DP)
- ccf 炉石传说
- CCF CSP 2016年9月第3题 炉石传说(模拟)
- ISBN号码-CCF模拟题
- CCF模拟题 窗口
- CCF炉石传说
- 201609-3 炉石传说 ccf
- CCF 201612-3 炉石传说 JAVA实现
- CCF 201609-3 炉石传说
- CCF模拟题 有趣的数