Who can help me!(悬关)
查看原帖
Who can help me!(悬关)
373288
cxy000楼主2024/11/22 21:22

总是50pts 能不能帮忙看看

#include <bits/stdc++.h>
using namespace std;
int L,R,m,n,tim,K,P,lim,cnt,x;
bool way[5][101][101];
bool born[100010];
int t[10010],bt[10010],blog[10010];
vector<int> mp[101][101];	//t指老鼠复活的时间
char c1,c2;
struct mice {
	bool died,small;
	int x,y,sex,to,c=1,tim;
} mou[100100];
struct bang {
	int ty,t,x,y;
} wea[1000100];
void chai(int x,int y,int now) {
	for(int i=8,p=4; i>=1; i/=2,p--) {
		if(now>=i) way[p][x][y]=1,now-=i;
	}
}
bool cmp(bang a,bang b) {
	return a.t<b.t;
}
void chang(int x,char c) {
	if(c=='N') mou[x].to=1;
	if(c=='E') mou[x].to=2;
	if(c=='S') mou[x].to=3;
	if(c=='W') mou[x].to=4;
}
void del(int x,int y,int L) {
	for(int i=1; i<=4; i++) {
		int l=x,r=y,op=0;
		if(i==1) {
			while(1) {
				if(mp[l][r].size()) {
					while(!mp[l][r].empty()) {
						op=mp[l][r].back();
						mou[op].died=1;
						mp[l][r].pop_back();
					}
				}
				l--;
				if(!way[i][l+1][r] || abs(l-x)>L) break;
			}
		}
		if(i==2) {
			while(1) {
				if(mp[l][r].size()) {
					while(!mp[l][r].empty()) {
						op=mp[l][r].back();
						mou[op].died=1;
						mp[l][r].pop_back();
					}
				}
				r++;
				if(!way[i][l][r-1] || abs(r-y)>L) break;
			}
		}
		if(i==3) {
			while(1) {
				if(mp[l][r].size()) {
					while(!mp[l][r].empty()) {
						op=mp[l][r].back();
						mou[op].died=1;
						mp[l][r].pop_back();
					}
				}
				l++;
				if(!way[i][l-1][r] || abs(l-x)>L) break;
			}
		}
		if(i==4) {
			while(1) {
				if(mp[l][r].size()) {
					while(!mp[l][r].empty()) {
						op=mp[l][r].back();
						mou[op].died=1;
						mp[l][r].pop_back();
					}
				}
				r--;
				if(!way[i][l][r+1] || abs(r-y)>L) break;
			}
		}
	}
}
double calc(int x1,int y1,int x2,int y2) {
	double dist=(double)sqrt((double)(x2-x1)*(double)(x2-x1)+(double)(y2-y1)*(double)(y2-y1));
	return dist;
}
void br(int x,int y,int tim) {
	for(int i=1; i<=4; i++) {
		if(way[i][x][y]) {
			//cout<<i<<" "<<x<<' '<<y<<" 2387482"<<endl;
			mou[++cnt].to=i;
			t[cnt]=tim+2;
			born[cnt]=1;
			mou[cnt].tim=tim+2;
			mou[cnt].small=1;
			mou[cnt].x=x;
			mou[cnt].y=y;
			if(i%2==0) mou[cnt].sex=1;
			else mou[cnt].sex=0;
		}
	}
	
}
void toward(int num,int x,int y,int to) {
	if(to==1 && way[1][x][y]) {
		mou[num].x--;
		return;
	}
	if(to==2 && way[2][x][y]) {
		mou[num].y++;
		return;
	}
	if(to==3 && way[3][x][y]) {
		mou[num].x++;
		return;
	}
	if(to==4 && way[4][x][y]) {
		mou[num].y--;
		return;
	}
	int ask=0;
	for(int i=1; i<=4; i++) {
		if(way[i][x][y]) ask++;
	}
	if(ask==3) {
		if(t[num]==0) {
			to--;if(to==0) mou[num].to=4;
			mou[num].c++;mou[num].to=to;
			return;
		}
		if(mou[num].c%2==1) {
			to--;if(to==0) mou[num].to=4;
			mou[num].to=to;
		} else {
			to++;if(to==5) mou[num].to=1;
			mou[num].to=to;
		}
		mou[num].c++;
		return;
	}
	if(ask==2) {
		if(t[num]==0) {
			//左减右加
			int xx=0;
			if(to>2) xx=to-2;
			else xx=to+2;
			if(!way[xx][x][y]) {
				to--;
				if(to==0) to=4;
				mou[num].to=to;
				mou[num].c++;//MOU[].c初始为1 
			} else {
				for(int i=1; i<=4; i++) {
					if(way[i][x][y] && i!=xx) {
						mou[num].to=i;
						return;
					}
				}
			}
			return;
		}
		int xx=0;
		if(to>2) xx=to-2;
		else xx=to+2;
		for(int i=1; i<=4; i++) {
			if(way[i][x][y] && i!=xx) {
				mou[num].to=i;
				return;
			}
		}
		return;
	}
	if(ask==1) {
		if(t[num]==0) {
			int xx=0;
			if(to>2) xx=to-2;
			else xx=to+2;
			if(way[xx][x][y]) t[num]=t[num]+2;
			else t[num]++;
			for(int i=1; i<=4; i++) {
				if(way[i][x][y]) mou[num].to=i;
			}
			return;
		}
		t[num]=t[num]+2;
		if(mou[num].to>2) mou[num].to-=2;
		else mou[num].to+=2;
		return;
	}
}
void wea1(int num) {
	if(wea[num].ty==1)
		del(wea[num].x,wea[num].y,L);
	else if(wea[num].ty==2) {
		for(int j=1; j<=cnt; j++) {
			double dis=calc(wea[num].x,wea[num].y,mou[j].x,mou[j].y);
			if(!mou[j].died && dis<=(double)R) {
				t[j]+=3;
			}
		}
	} else if(wea[num].ty==3) {
		for(int j=1; j<=cnt; j++) {
			if(!mou[j].died && mou[j].x==wea[num].x && mou[j].y==wea[num].y) {
				mou[j].died=1;
			}
		}
	} else if(wea[num].ty==4) {
		for(int j=1; j<=cnt; j++) {
			if(!mou[j].died && mou[j].x==wea[num].x && mou[j].y==wea[num].y) {
				mou[j].sex=mou[j].sex xor 1;
			}
		}
	}
}
int main() {
	//0 先走 -->炸弹炸-->繁殖
	cin>>L>>R>>m>>n;
	for(int i=1; i<=m; i++)
		for(int j=1; j<=n; j++)
			cin>>x,chai(i,j,x);
	cin>>K;cnt=K;
	for(int i=1; i<=K; i++) {
		cin>>mou[i].x>>mou[i].y>>c1>>c2;
		chang(i,c1);
		born[i]=0;
		if(c2=='X') mou[i].sex=1;
		else mou[i].sex=0;//1雄  0雌
	}
	cin>>P>>lim;
	for(int i=1; i<=P; i++) {
		cin>>wea[i].ty>>wea[i].t>>wea[i].x>>wea[i].y;
		if(wea[i].ty==3) wea[i].t+=3;
	}
	cin>>tim;
	sort(wea+1,wea+1+P,cmp);
	int tic=wea[1].t,num=1,numm=0;
	for(int j=1; j<=cnt; j++)
		toward(j,mou[j].x,mou[j].y,mou[j].to);
	for(int j=1; j<=cnt; j++) {
		if(!mou[j].died) {
			mp[mou[j].x][mou[j].y].push_back(j);
		}
	}
	for(int i=1; i<=tim; i++) {
//		cout<<i<<endl;
//		cout<<numm<<" 11451419"<<endl;
//		for(int i=1;i<=cnt;i++) cout<<mou[i].small<<" ";
//		cout<<"\n\n";
//		for(int j=1; j<=m; j++) {
//			for(int k=1; k<=n; k++) {
//				cout<<mp[j][k].size()<<" ";
//			}
//			cout<<endl;
//		}
//		cout<<endl;
		for(int j=1; j<=cnt; j++) {
			if(t[j]<i) t[j]=i;
		}
		while(i==tic) {
			wea1(num);tic=wea[++num].t;
		}
		for(int j=K+1; j<=cnt; j++) {
			if(i>=t[j] && born[j]) born[j]=0;
			if(i-mou[j].tim>=5) mou[j].small=0;
		}
		for(int j=1; j<=cnt; j++) {
			if(born[j] || t[j]>i) continue;
			toward(j,mou[j].x,mou[j].y,mou[j].to);
		}
		for(int j=1; j<=m; j++) {
			for(int k=1; k<=n; k++) mp[j][k].clear();
		}
		for(int j=1; j<=cnt; j++) {
			//	if(t[j]>i) continue;
			if(!mou[j].died) {
				mp[mou[j].x][mou[j].y].push_back(j);
			}
		}
		for(int j=1; j<=m; j++) {
			for(int k=1; k<=n; k++) {
				if(mp[j][k].size()<2 || mp[j][k].size()>2) continue;
				if(mou[mp[j][k][0]].small || mou[mp[j][k][1]].small) continue;
				if(t[mp[j][k][0]]>i || t[mp[j][k][1]]>i) continue;
				if(mou[mp[j][k][0]].sex!=mou[mp[j][k][1]].sex) {
					br(j,k,i);
					t[mp[j][k][0]]=i+3;t[mp[j][k][1]]=i+3;
				}
			}
		}
		for(int j=1; j<=cnt; j++) {
			//	if(t[j]>i) continue;
			if(!mou[j].died) {
				mp[mou[j].x][mou[j].y].push_back(j);
			}
		}
		numm=0;
		for(int j=1; j<=cnt; j++) {
			if(!mou[j].died && !born[j]) numm++;
		}
		if(numm>lim) {
			cout<<"-1";
			return 0;
		}
	}
	for(int j=1;j<=cnt;j++) {if(!mou[j].died && !born[j]) numm++;}
	cout<<numm<<endl;
	/*
	N 1 北方
	E 2 东方
	S 4 南方
	W 8 西方
	*/
	return 0;
}
2024/11/22 21:22
加载中...