求助
2024-04-29 14:01:46
发布于:浙江
(代码较长,耐心)
题目
数据:
3 10
MP D D F F
ZP N N N D
FP J J J J
F F D D J J F F K D
正确输出(算DEBUG):
round 0
0sC: D
0sC: D
0sC: F
0sC:F
1sC:N
1 use a N,id:0
1sC:N
1 use a N,id:1
1sC:N
1 use a N,id 2
1sC:D
2sC: J
2sC: J
2sC: J
2sC: J
round 1
0sC: D
0sC: D
0sC: F
0 use a F,id:2
0sC:F
0 use a F,id:3
0sC: F
0 use a F,id:4
0sC:F
0 use a F,id:5
2sC: J
2sC: J
2sC: J
2sC: J
2sC: J
2sC: J
round 2
0sC:F
0sC:F
2sC: J
2sC: J
2sC: J
2sC: J
2sC: J
2sC: J
2sC:K
2 use a K,id:6
FP
DEAD
DEAD
J J J J J J D
我的输出:
round 0
0sC: D
0sC: D
0sC: F
0sC: F
1sC: N
1 use a N,id:0
1sC: N
1 use a N,id:1
1sC: N
1 use a N,id:2
1sC: D
2sC: J
2sC: J
2sC: J
2sC: J
0sC: D
0sC: D
0sC: F
0 use a F,id:2
0sC: D
0sC: F
0 use a F,id:3
2sC: J
2sC: J
2sC: J
2sC: J
0sC: D
……(上方五行*INF)
MY CODE(BUG应该在主函数):
#include <bits/stdc++.h>
using namespace std;
struct pig{
string idt;//身份
vector<pair<char,bool> > cards;//卡组
bool die=0,pzhu=0;//是否死了,是否装了猪哥连弩,是否跳了
int hp=4,id,mp=-1,pre,next,jp=0;
}pigs[15];
int fpnum=0,win=-1;//win=-1:not,win=0:MP win,win=1:FP win
queue<char> cp;
int n,m;
void tfd(int now,int know){//是否会死,凶手是谁
for (int i=pigs[now].next;i!=now;i=pigs[i].next){
if (pigs[now].cards[i].first=='P' && !pigs[now].cards[i].second){
pigs[now].cards[i].second=1;
pigs[now].hp+=1;
if (pigs[now].hp>0){
return ;
}
}
}
pigs[now].die=1;
pigs[pigs[now].pre].next=pigs[now].next;
pigs[pigs[now].next].pre=pigs[now].pre;
if (now==0){
win=1;
return ;
}
if (pigs[now].idt=="FP"){
fpnum-=1;
if (fpnum==0){
win=0;
return ;
}
pigs[know].cards.push_back({cp.front(),0});
cp.pop();
pigs[know].cards.push_back({cp.front(),0});
cp.pop();
pigs[know].cards.push_back({cp.front(),0});
cp.pop();
}else if (pigs[now].idt=="ZP" && know==0){
pigs[0].cards.clear();
pigs[0].pzhu=0;
}
}
void use_d(int now){//用闪
bool f=0;
for (int i=0;i<pigs[now].cards.size();++i){
if (pigs[now].cards[i].first=='D' && !pigs[now].cards[i].second){
f=1;
pigs[now].cards[i].second=1;
break;
}
}
if (!f){
pigs[now].hp-=1;
}
}
bool use_j(int now,int z_f){//用无懈可击
int p=now;
do{
if (pigs[p].idt!="FP" && z_f==1){
for (int i=0;i<pigs[p].cards.size();++i){
if (pigs[p].cards[i].first=='J' && pigs[p].cards[i].second){
pigs[p].cards[i].second=1;
pigs[p].jp=1;
return !use_j(p,2);
}
}
}
if (pigs[p].idt=="FP" && z_f==2){
for (int i=0;i<pigs[p].cards.size();++i){
if (pigs[p].cards[i].first=='J' && pigs[p].cards[i].second){
pigs[p].cards[i].second=1;
pigs[p].jp=1;
return !use_j(p,1);
}
}
}
p=pigs[p].next;
}while (p!=now);
return 0;
}
void fight(int fi,int fj){
if (fi==0 && pigs[fj].idt=="ZP"){
pigs[fj].hp-=1;
if (pigs[fj].hp<=0){
tfd(fj,fi);
}
return ;
}
int l=fj;
while (1){
bool f=0;
for (int i=0;i<pigs[l].cards.size();++i){
if (pigs[l].cards[i].first=='K' && !pigs[l].cards[i].second){
f=1;
pigs[l].cards[i].second=1;
break;
}
}
if (!f){
pigs[l].hp-=1;
if (pigs[l].hp<=0){
tfd(l,(fi+fj)-l);
}
break;
}else{
l=(fi+fj)-l;
}
}
}
bool use_f(int now){//用决斗
if (pigs[now].idt=="FP"){
pigs[now].jp=1;
if (!use_j(now,0)){
fight(now,0);
}
return 1;
}else if (pigs[now].idt=="ZP"){
for (int i=pigs[now].next;i!=now;i=pigs[i].next){
if (pigs[i].jp==1 && pigs[i].idt=="FP"){
pigs[now].jp=1;
bool f=0;
if (pigs[i].jp==1){
f=use_j(now,2);
}
if (!f){
fight(now,i);
}
return 1;
}
}
}else{
for (int i=pigs[now].next;i!=now;i=pigs[i].next){
if ((pigs[i].jp==1 && pigs[i].idt=="FP") || pigs[i].jp==2){
pigs[now].jp=1;
bool f=0;
if (pigs[i].jp==1){
f=use_j(now,2);
}
if (!f){
fight(now,i);
}
return 1;
}
}
}
return 0;
}
bool use_n(int now){//用南猪入侵
for (int i=pigs[now].next;i!=now;i=pigs[i].next){
bool f=0;
if (pigs[i].jp==1){
if (use_j(now,pigs[i].idt=="MP"?1:(pigs[i].idt=="ZP"?1:2))){
continue;
}
}
for (int j=0;j<pigs[i].cards.size();++j){
if (pigs[i].cards[j].first=='K' && !pigs[i].cards[j].second){
f=1;
pigs[i].cards[j].second=1;
break;
}
}
if (!f){
pigs[i].hp-=1;
if (pigs[i].hp<=0){
tfd(i,now);
}
if (i==0 && pigs[now].jp==0){
pigs[now].jp=2;
}
if (win!=-1){
return 1;
}
}
}
return 1;
}
bool use_w(int now){//用万箭齐发
for (int i=pigs[now].next;i!=now;i=pigs[i].next){
bool f=0;
if (pigs[i].jp==1){
if (use_j(now,pigs[i].idt=="MP"?1:(pigs[i].idt=="ZP"?1:2))){
continue;
}
}
for (int j=0;j<pigs[i].cards.size();++j){
if (pigs[i].cards[j].first=='D' && !pigs[i].cards[j].second){
f=1;
pigs[i].cards[j].second=1;
break;
}
}
if (!f){
pigs[i].hp-=1;
if (pigs[i].hp<=0){
tfd(i,now);
if (win!=-1){
return 1;
}
}
if (i==0 && pigs[now].jp==0){
pigs[now].jp=2;
}
if (win!=-1){
return 1;
}
}
}
return 1;
}
bool use_p(int now){//用桃
if(pigs[now].hp<4){
pigs[now].hp+=1;
return 1;
}else{
return 0;
}
}
bool use_k(int now){//用杀
if (pigs[now].idt=="FP"){
if (pigs[pigs[now].next].jp==1 && pigs[pigs[now].next].idt!="FP"){
pigs[now].jp=1;
use_d(pigs[now].next);
if (pigs[pigs[now].next].hp<=0){
tfd(pigs[now].next,now);
}
}
return 1;
}else if (pigs[now].idt=="ZP"){
if (pigs[pigs[now].next].jp==1 && pigs[pigs[now].next].idt=="FP"){
pigs[now].jp=1;
use_d(pigs[now].next);
if (pigs[pigs[now].next].hp<=0){
tfd(pigs[now].next,now);
}
}
return 1;
}else{
if ((pigs[pigs[now].next].jp==1 && pigs[pigs[now].next].idt=="FP") || (pigs[pigs[now].next].jp==2)){
use_d(pigs[now].next);
if (pigs[pigs[now].next].hp<=0){
tfd(pigs[now].next,now);
}
}
return 1;
}
return 0;
}
bool use_z(int now){//用猪哥连弩
pigs[now].pzhu=1;
return 1;
}
int main()
{
cin>>n>>m;
for (int i=0;i<n;++i){
string s;
cin>>s;
if (s=="FP"){
fpnum+=1;
}
pigs[i].idt=s;
pigs[i].id=i;
pigs[i].pre=(i-1+n)%n;
pigs[i].next=(i+1)%n;
for (int j=0;j<4;++j){
char c;
cin>>c;
pigs[i].cards.push_back({c,0});
}
}
char z;
for (int i=0;i<m;++i){
char c;
cin>>c;
if (i==m-1){
z=c;
}
cp.push(c);
}
for (int i=0;i<5000;++i){
cp.push(z);
}
int num=0;
while (win==-1){
cout<<"round "<<num++<<endl<<endl;
for (int i=0;i<n;i=pigs[i].next){
if (pigs[i].die){
continue;
}
bool use_1_k=0,it_use=0;
for (int j=0;j<pigs[i].cards.size();++j){
if (!pigs[i].cards[j].second){
cout<<i<<"sC: "<<pigs[i].cards[j].first<<endl;
if (pigs[i].cards[j].first=='P'){
it_use=use_p(i);
if (it_use){
cout<<i<<" use a P,id:"<<j<<endl;
}
}else if (pigs[i].cards[j].first=='K'){
if (!use_1_k || pigs[i].pzhu){
it_use=use_k(i);
if (it_use){
use_1_k=1;
cout<<i<<" use a K,id:"<<j<<endl;
}
}
}else if (pigs[i].cards[j].first=='F'){
it_use=use_f(i);
if (it_use){
cout<<i<<" use a F,id:"<<j<<endl;
}
}else if (pigs[i].cards[j].first=='N'){
it_use=use_n(i);
if (it_use){
cout<<i<<" use a N,id:"<<j<<endl;
}
}else if (pigs[i].cards[j].first=='W'){
it_use=use_w(i);
if (it_use){
cout<<i<<" use a W,id:"<<j<<endl;
}
}else if (pigs[i].cards[j].first=='Z'){
it_use=use_z(i);
if (it_use){
cout<<i<<" use a Z,id:"<<j<<endl;
}
}
if (it_use){
pigs[i].cards[j].second=1;
j=0;
}
if (pigs[i].die){
break;
}
if (win!=-1){
break;
}
}
}
if (win!=-1){
break;
}
}
for (int i=0;i<n;++i){
if (!pigs[i].die){
pigs[i].cards.push_back({cp.front(),0});
cp.pop();
pigs[i].cards.push_back({cp.front(),0});
cp.pop();
}
}
}
if (win==0){
cout<<"MP"<<endl;
}else{
cout<<"FP"<<endl;
}
for (int i=0;i<n;++i){
if (pigs[i].die){
cout<<"DEAD"<<endl;
}else{
for (int j=0;j<pigs[i].cards.size();++j){
if (!pigs[i].cards[j].second){
cout<<pigs[i].cards[j].first<<" ";
}
}
cout<<endl;
}
}
return 0;
}
求大佬帮助。
全部评论 11
顶
2024-05-02 来自 浙江
0顶
2024-05-01 来自 浙江
0顶
2024-04-30 来自 浙江
0几百行啊
2024-04-29 来自 广东
0这这这这我手又要爆缸
2024-04-29 来自 广东
0我类和骚杠
2024-04-29 来自 广东
0d
2024-04-29 来自 浙江
0救命,超级大模拟题目。
2024-04-28 来自
0哇,出现了!大佬,快使用大师球抓捕他吧。
2024-04-28 来自 浙江
1interesting
2024-04-29 来自
0
顶
2024-04-28 来自 浙江
0顶
2024-04-28 来自 浙江
0顶
2024-04-27 来自 浙江
0
有帮助,赞一个