问题:#1 RE,下载数据本地运行正确
测试点返回信息:
Recived signal 11: Segmentation fault with invalid memory reference.
代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
/*
主猪:MP
忠猪:ZP
反猪: FP
桃:P
杀:K
闪:D
决斗:F
南猪入侵:N
万箭齐发:W
无懈可击:J -- 帮别人挡是献殷勤,挡别人的献殷勤是表敌意
猪哥连弩:Z
初始体力/上限:4
*/
int n, m, mp, fz, sta;
vector<char> stack1, card_stack;
struct player{
char id, app;
int hp, lst, nxt;
vector<char> card;
bool equiped, dead;
} newp;
vector<player> pig;
int next(int x);
int relat(int x, int y);
bool find_card(int x, char y);
void die(int from, int x);
void lohp(int from, int to);
void fakef(int from, int to);
void get_card(int x, int num);
void attack(int from, int to);
void kill(int from, int to);
void play(int x);
int main(){
// freopen("test1.in","r",stdin);
scanf("%d%d",&n,&m);
newp.hp = 4;
newp.equiped = 0;
newp.dead = 0;
for(int i=1; i<=n; ++i){
newp.app = 'U';
newp.card.clear();
getchar();
newp.id = getchar();
if(newp.id=='M')
mp=i-1, newp.app='M';
else if(newp.id=='F') ++fz;
getchar();
for(int j=1; j<=4; ++j)
getchar(),
newp.card.push_back(getchar());
newp.nxt = i;
newp.lst = i-2;
pig.push_back(newp);
}
pig[0].lst = n-1;
pig[n-1].nxt = 0;
for(int i=1; i<=m; ++i)
getchar(),
card_stack.push_back(getchar());
reverse(card_stack.begin(), card_stack.end());
int i=0;
while(!sta){
get_card(i, 2);
play(i);
i = next(i);
}
if(sta==1) printf("MP\n");
else printf("FP\n");
for(int i=0; i<n; ++i)
if(pig[i].dead) printf("DEAD\n");
else{
for(int j=0; j<pig[i].card.size(); ++j){
char a = pig[i].card[j];
if(a!=' ') printf("%c ",a);
}
printf("\n");
}
return 0;
}
int next(int x){
return pig[x].nxt;
} // 寻找下一玩家
void get_card(int x, int num){
for(int i=1; i<=num; ++i){
pig[x].card.push_back(card_stack.back());
if(card_stack.size()>1) card_stack.pop_back();
}
return;
} // 抽卡
void play(int x){
bool kil=0;
for(int i=0; i<pig[x].card.size(); ++i){
char *a = &pig[x].card[i];
if(*a==' ') continue;
else if(*a=='P' && pig[x].hp<4)
++pig[x].hp, *a = ' ';
else if(*a=='K' && (!kil || pig[x].equiped)){
int ne = next(x);
if(relat(x,ne)<0)
kill(x,ne), kil=1, *a = ' ';
}
else if(*a=='Z'){
if(!pig[x].equiped)
for(int j=0; j<i; ++j){
if(pig[x].card[j]=='K'){
int ne = next(x);
if(relat(x, ne)<0)
kill(x,ne), pig[x].card[j] = ' ';
}
}
*a = ' ', pig[x].equiped=1;
}
if(sta) return;
}
return;
} // 出卡
int relat(int x, int y){
if(pig[y].app=='F')
if(pig[x].id=='M') return -1;
if(pig[y].app!=pig[y].id) return 0;
if(pig[x].id==pig[y].id) return 1;
if(pig[y].id+pig[x].id==char(167)) return 1;
return -1;
}; // 判断出牌方与对方关系
void attack(int from, int to){
if(pig[from].id==pig[from].app) return;
if(pig[to].id=='F' && pig[to].app=='F' && pig[from].id=='Z')
pig[from].app='Z';
else if(pig[to].id=='Z' && pig[to].app=='Z' && pig[from].id=='F')
pig[from].app='F';
else if(pig[to].id=='M' && pig[from].id=='F') pig[from].app='F';
return;
} // 表敌意
void fakef(int from, int to){
if(pig[to].id=='M' && pig[from].app=='U') pig[from].app='F';
return;
} // 设置类反猪
bool find_card(int x, char y){
for(int i=0; i<pig[x].card.size(); ++i)
if(pig[x].card[i]==y){
pig[x].card[i]=' ';
return true;
}
return false;
} // 找卡 & 出卡
void lohp(int from, int x){
if(pig[x].hp==1){
if(!find_card(x, 'P'))
die(from, x);
}
else --pig[x].hp;
return;
} // 扣血
void die(int from, int x){
pig[x].dead=1;
pig[x].card.clear();
pig[pig[x].lst].nxt = pig[x].nxt;
pig[pig[x].nxt].lst = pig[x].lst;
if(pig[x].id=='M') sta=-1;
else if(pig[x].id=='F'){
if(!--fz) sta=1;
else get_card(from, 3);
}
else if(pig[from].id=='M'){
pig[from].card.clear();
pig[from].equiped = 0;
}
return;
} // 死亡
void kill(int from, int to){
attack(from, to);
if(!find_card(to, 'D')){
lohp(from, to);
}
return;;
} // 出杀
另:本蒟蒻目标只是80',还请大佬理解