版本比较
题解 P2482 【[SDOI2010]猪国杀】
正文
增加 14 行删除 14 行
9 行未改动10111213141415161718120 行未改动全部展开13914014114214314314414514614766 行未改动2142152162172182182192202212227 行未改动23023123223323423423523623723873 行未改动31231331431531631631731831932017 行未改动33833934034134234234334434534651 行未改动39839940040140240240340440540640740840940941041141241364 行未改动47847948048148248248348448548648748848949049149249249349449549647 行未改动5445455465475485485495505515527 行未改动56056156256356456456556656756856956957057157257317 行未改动59159259359459559559659759859988 行未改动9 行未改动 2.无懈可击可以循环释放,最好用递归实现。 3.要实时更新每只猪的显现身份和存活情况,遇到游戏结束及时返回。 4.除了桃以外,其他所有的牌释放后都必须从第一张开始重新模拟,因为前面的牌可能又能够使用了。 5.牌堆没有牌时,要不断最后一张牌。
下面是程序分段讲解:
### $Part0:$定义和小函数
120 行未改动全部展开bool friendly(int x,int y){//同理 if (pig[y].pigid==0) return false; if (pig[x].id!=3 && pig[y].pigid!=3) return true; if (pig[x].id==3 && pig[y].pigid==3) return true; return false; return false;}void getfriend(int x,int y){ if (pig[y].pigid==0) return;//如果y没有显露身份,交朋友没有意义 if (pig[y].pigid!=3) pig[x].special=false,pig[x].pigid=1;//否则就显露和y相同的身份,记得处理类反猪的头衔。66 行未改动 } dechp(from,to);//扣血 } } to=pig[to].nxt; to=pig[to].nxt; if (to==from) return;//一圈轮完,就退出 }}void usecard_w(int from,int to){//万箭齐发7 行未改动 } dechp(from,to); } } to=pig[to].nxt; to=pig[to].nxt; if (to==from) return; }}```73 行未改动
由于所有部分都已经讲完了,所以直接上代码。```void rungame(){ while (true){//游戏一直运行下去 while (true){//游戏一直运行下去 for (int i=1;i<=n;++i){ if (gameover) return;//实时准备游戏结束 if (pig[i].hp<=0) continue;//猪死了就直接跳过 getcard(i);getcard(i);//摸牌17 行未改动 use_k=false;//没有连弩的话就不能再出杀了 } j=0;//从头再来,因为整个场面可能发生改变 } break; break; } case 'F':{//决斗,相对来说难实现一些 if (pig[i].id==3){//如果是反猪,目标就是主猪 pig[i].card[j]='X';51 行未改动using namespace std;#define N 11#define M 2222struct player{ int id; int id; int hp; int cnt; char card[M]; int pre; int nxt; int pigid; bool special; bool special; bool weapon;}pig[N];int n,m;int top;64 行未改动 pig[pig[i].nxt].pre=pig[i].pre; }}bool enemy(int x,int y){ if (pig[x].id==1 && pig[y].special==true) return true; if (pig[x].id==1 && pig[y].special==true) return true; if (pig[y].pigid==0) return false; if (pig[x].id!=3 && pig[y].pigid==3) return true; if (pig[x].id==3 && pig[y].pigid!=3) return true; return false;}bool friendly(int x,int y){ if (pig[y].pigid==0) return false; if (pig[x].id!=3 && pig[y].pigid!=3) return true; if (pig[x].id==3 && pig[y].pigid==3) return true; return false; return false;}
bool usecard_j(int from,int to,int last){ int now=from;47 行未改动 } dechp(from,to); } } to=pig[to].nxt; to=pig[to].nxt; if (to==from) return; }}void usecard_w(int from,int to){7 行未改动 } dechp(from,to); } } to=pig[to].nxt; to=pig[to].nxt; if (to==from) return; }}void rungame(){ while (true){ while (true){ for (int i=1;i<=n;++i){ if (gameover) return; if (pig[i].hp<=0) continue; getcard(i);getcard(i);17 行未改动 use_k=false; } j=0; } break; break; } case 'F':{ if (pig[i].id==3){ pig[i].card[j]='X';88 行未改动