首页 > 其他分享 >关于猪国杀

关于猪国杀

时间:2022-10-04 19:45:34浏览次数:71  
标签:猪国 int sp erase 关于 now dr out

从今天下午开始看题 于2022.10.4 19:26:23在 \(loj\) \(ac\)

没有大改,没有重构,框架一遍过

下面是原版代码

code
#include<bits/stdc++.h>
using namespace std;
#define MP 3
#define ZP 1
#define FP 2
char in[100];
int n, m;
char muopai(){
	if(m){
		cin >> in;
		--m;
	}
	return in[0];
}
int cntfp;
struct PIG{
	int sf;//身份 1 忠 2 反 3 主
	bool jump_zhong, jump_fan, lei_fan, have_zhuangbei;
	int hp;
	int nxt, id, from;
	vector<char>sp;//手牌
	void mp(int x){//摸牌,张数
		for(int i = 1; i <= x; ++i)sp.push_back(muopai());
		// cout << " I mp :: ";
		// for(char c : sp)cout << c << " " ;
		// cout << endl;
	}
}p[15];
bool game_over;

void MAKE_DR(int from, int to){
	// cout << from << "bdy to " << to << endl;
	if(p[from].sf == MP)return;
	if(p[to].sf == MP || p[to].jump_zhong){p[from].jump_fan = 1;return;}
	if(p[to].jump_fan){p[from].jump_zhong = 1;return;}
}
void MAKE_FRIEND(int from, int to){
	// cout << from << " xyq to " << to << endl;
	if(p[to].sf == MP)p[from].jump_zhong = 1, p[from].lei_fan = 0;
	p[from].jump_fan |= p[to].jump_fan;
	p[from].jump_zhong |= p[to].jump_zhong;
}
void NEED_TAO(int x, int from){
	auto y = p[x].sp.begin();
	for(; y != p[x].sp.end(); ++y)if((*y) == 'P'){p[x].sp.erase(y); ++p[x].hp; return;}
	p[p[x].from].nxt = p[x].nxt;
	p[p[x].nxt].from = p[x].from;
	if(p[x].sf == MP){game_over = 1; return;}
	if(p[x].sf == ZP && p[from].sf == MP){p[from].sp.clear(); p[from].have_zhuangbei = 0; return;}
	if(p[x].sf == FP){--cntfp; if(cntfp == 0){game_over = 1; return;} p[from].mp(3);}
}
bool NEED_SHAN(int x){
	auto y = p[x].sp.begin();
	for(; y != p[x].sp.end(); ++y)if((*y) == 'D'){p[x].sp.erase(y);return true;}
	return false;
}
bool NEED_SHA(int x){
	auto y = p[x].sp.begin();
	for(; y != p[x].sp.end(); ++y)if((*y) == 'K'){p[x].sp.erase(y);return true;}
	return false;
}
bool NEED_WXKJ(int x){
	auto y = p[x].sp.begin();
	for(; y != p[x].sp.end(); ++y)if((*y) == 'J'){p[x].sp.erase(y);return true;}
	return false;
}
void USE_KILL(int from, int to){
	// cout << from << "use KILL to" << to << endl;
	if(p[from].sf != MP || p[to].sf != ZP)MAKE_DR(from, to);
	if(!NEED_SHAN(to)){--p[to].hp; if(p[to].hp < 1)NEED_TAO(to, from);}
}

bool check_make_friend(int now, int x){
	if(p[x].sf == MP && (p[now].sf == ZP || p[now].sf == MP))return true;
	if(p[x].jump_zhong && (p[now].sf == MP || p[now].sf == ZP))return true;
	if(p[x].jump_fan && p[now].sf == FP)return true;
	return false;
}
bool check_make_dr(int now, int x){
	if(now == x)return false;
	if(p[x].sf == MP && p[now].sf == FP)return true;
	if(p[x].jump_fan && (p[now].sf == MP || p[now].sf == ZP))return true;
	if(p[x].jump_zhong && p[now].sf == FP)return true;
	if(p[x].lei_fan && p[now].sf == MP)return true;
	return false;
}
bool get_WXKJ_dr(int x){
	int now = p[x].nxt;
	while(now != x){
		if(check_make_dr(now, x) && NEED_WXKJ(now)){
			MAKE_DR(now, x);
			if(get_WXKJ_dr(now) == false)return true;
			else return false;
		}
		now = p[now].nxt;
	}
	return false;
}
bool get_WXKJ_friend(int x, int used){
	int now = used;
	do{
		// if(now == 5 && x == 4)cout << check_make_friend(now, x) << " " << p[x].jump_fan << endl;
		if(check_make_friend(now, x) && NEED_WXKJ(now)){
			MAKE_FRIEND(now, x);
			if(get_WXKJ_dr(now) == false)return true;
			else return false;
		}
		now = p[now].nxt;
	}while(now != used);
	return false;
}

void USE_FIGHT(int from, int to){
	if(p[from].sf == MP && p[to].sf == ZP){
		if(get_WXKJ_friend(to, from))return;
		--p[to].hp;
		if(p[to].hp < 1)NEED_TAO(to, from);
		return;
	}
	MAKE_DR(from, to);
	if(get_WXKJ_friend(to, from))return;
	for(int round = 1; true; ++round){
		if(round & 1){
			if(NEED_SHA(to))continue;
			--p[to].hp;
			if(p[to].hp < 1)NEED_TAO(to, from);
		}
		else {
			if(NEED_SHA(from))continue;
			--p[from].hp;
			if(p[from].hp < 1)NEED_TAO(from, to);
		}
		break;
	}
}
void USE_NZRQ(int from){
	// cout << from << " used NZRQ" << endl;
	int now = p[from].nxt;
	while(now != from){
		int nxt = p[now].nxt;
		if(!get_WXKJ_friend(now, from))
			if(!NEED_SHA(now)){
				--p[now].hp;
				if(p[now].sf == MP)p[from].lei_fan = 1;
				if(p[now].hp < 1)NEED_TAO(now, from);
			}
		if(game_over)return;
		now = nxt;
	}
	// cout << p[now].hp << " " << p[now].jump_fan << " " << p[now].jump_zhong << " " << p[now].lei_fan << endl;

}
void USE_WJQF(int from){
	// cout << from << " used WJQF" << endl;
	int now = p[from].nxt;
	while(now != from){
		int nxt = p[now].nxt;
		if(!get_WXKJ_friend(now, from))
			if(!NEED_SHAN(now)){
				--p[now].hp;
				if(p[now].sf == MP)p[from].lei_fan = 1;
				if(p[now].hp < 1)NEED_TAO(now, from);
			}
		if(game_over)return;
		now = nxt;
	}
}
void print(){
	// for(int i = 1; i <= n; ++i){
	// 	cout << i << " " << p[i].hp << " ";
	// 		if(p[i].hp > 0){
	// 		for(char c : p[i].sp)cout << c << " ";
	// 		cout << endl;
	// 	}else cout << "DEAD\n";
	// }
	// cout << endl;
		// for(int i = 1; i <= n; ++i)cout << p[i].from << " " << p[i].nxt << "  ";

	// cout << endl;
}
int find_DR(int now){
	int l = p[now].nxt;
	while(l != now){
		if(p[l].hp < 1){
			l = p[l].nxt;
			continue;
		}
		if(p[now].sf == FP){
			if(p[l].sf == MP)return l;
			if(p[l].jump_zhong)return l;
		}
		if(p[now].sf == ZP){
			if(p[l].jump_fan)return l;
		}
		if(p[now].sf == MP){
			if(p[l].jump_fan ||(!p[l].jump_zhong && p[l].lei_fan))return l;
		}
		l = p[l].nxt;
	}
	return 0;
}
void play(int now){
	bool out = 1, CAN_KILL = 1;
	while(out && !game_over && p[now].hp > 0){
		out = 0;
		auto x = p[now].sp.begin();
		for(; x != p[now].sp.end(); ++x){
			if((*x) == 'P' && p[now].hp < 4){
				++p[now].hp; out = 1; p[now].sp.erase(x); break;
			}
			if((*x) == 'K' && (CAN_KILL || p[now].have_zhuangbei)){
				int dr = find_DR(now);
				if(dr == p[now].nxt){
					out = 1; CAN_KILL = 0;
					p[now].sp.erase(x);
					USE_KILL(now, dr);
					break;
				}
			}
			if((*x) == 'F'){
				int dr = find_DR(now);
				if(p[now].sf == FP)dr = 1;
				if(dr){
					out = 1;
					p[now].sp.erase(x);
					USE_FIGHT(now, dr);
					break;
				}
			}
			if((*x) == 'N'){
				p[now].sp.erase(x);
				out = 1;
				USE_NZRQ(now);
				break;
			}
			if((*x) == 'W'){
				p[now].sp.erase(x);
				out = 1;
				USE_WJQF(now);
				break;
			}
			if((*x) == 'Z'){
				p[now].have_zhuangbei = 1;
				p[now].sp.erase(x);
				out = 1;
				break;
			}
		}
		if(out)print();
	}
}

void start_game(){
	int now = 1;
	do{
		if(p[now].hp < 1){
			now = p[now].nxt;
			continue;
		}
		// cout << now << " ";
		p[now].mp(2);
		play(now);
		now = p[now].nxt;
	}while(!game_over);
}

int main(){
	cin >> n >> m;
	m += n * 4;
	for(int i = 1; i <= n; ++i){
		cin >> in;
		if(in[0] == 'M')p[i].sf = MP;
		if(in[0] == 'Z')p[i].sf = ZP;
		if(in[0] == 'F')p[i].sf = FP, ++cntfp;
		p[i].mp(4); p[i].hp = 4; p[i].nxt = i + 1; p[i].id = i; p[i].from = i - 1;
	}
	p[1].from = n;
	p[n].nxt = 1;
	start_game();
	if(cntfp)cout << "FP\n";
	else cout << "MP\n";
	for(int i = 1; i <= n; ++i)if(p[i].hp > 0){
		for(char c : p[i].sp)cout << c << " ";
		cout << endl;
	}else cout << "DEAD\n";
	return 0;
}

标签:猪国,int,sp,erase,关于,now,dr,out
From: https://www.cnblogs.com/Chencgy/p/16754291.html

相关文章

  • Oracle-关于shutdown immediate的一次手滑
    首先,明确的一点是,操作习惯非常重要。尽量不要多窗口同时操作!尽量不要多窗口同时操作!尽量不要多窗口同时操作!重要的事情说三遍。尤其是在操作生产环境的时候。涉及到变更的操......
  • 关于Android开发工具的下载之ADT篇
    ADT的下载首先可以选择下面推荐的两个网站去下载相应的安装包,网址如下:http://tools.android-studio.org/index.php/adt-bundle-plugin或者http://www.androiddevtools.......
  • redis一些关于SessionCallback和事务要注意的地方
     文章目录1.redisTemplate2.StringRedisTemplate3.测试SessionCallBack4.redis相关的同样适用lambda5.RedisSessionCallback和redis事务的区别......
  • 关于如何自律
    国庆节我却依旧颓废。从早上起床到下午4点。一直无法专注思考也没怎么学习。救命。感觉自己就要废掉了。算法学不下去。也不想学whk。难道我就是这样一个人吗。......
  • 关于python函数中带*星号参数-收集参数的使用说明
    在python中,定时函数时,一般就得确定函数的参数的个数当然函数可以没有参数,也可以指定明确的形式参数的个数,那样在调用这个函数时,实参的个数就需要与形参个数一致defPrin......
  • 关于MC服务器的优化启动
    azul的zing优化jdk可以免费体验实际使用的时候却发现经常闪退,需要用以下参数运行java-Xms10G-Xmx10G-XX:+UseShenandoahGC-XX:+UseTrueObjectsForUnsafe-XX:+Paral......
  • 关于使用ADB无线连接安卓手机的几点说明。
    一、adb无线连接对安卓版本基本没有限制,现已知安卓7开调试模式和信任设备,即可以无线连接;二、原连接步骤:1、有线连接:adbtcpip488872、设备列表:adbdevices-l......
  • Effective C++ - 条款7 - 关于基类的virtual析构和non-virtual析构
    如果基类的析构是non-virtual的,在使用baseclass指针指向一个derived对象,并且这个对象由baseclass指针删除时,derived对象的成分并没有被删除,原因是baseclass定义了一个n......
  • 关于苏敏阿姨
    听到了她的事迹,别人都夸她的勇敢,但我感到一种沉痛的伤感,有一段失败的婚姻真的很可怕。爱一个是最难的是放手,你要在她不喜欢你的时候去放手,放她去追寻自己的自由。......
  • 关于 SAP UI5 ODataModel.createEntry 返回的 context 对象
    在返回的上下文中使用创建的API返回的Promise对象,以便在持久化或重置时获得通知。使用isTransientAPI,您可以确定创建的上下文是transient的还是持久的;请注意,对于尚......