跳到正文

个人记录

test

Fenwick约 4 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年6月21日
篇幅
约 4 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h> // 头文件
using namespace std; // 命名空间
int n,m,p; // 题意
vector<string>power;//玩家名称
vector<vector<string>>maps;//地图
map<string,pair<int,int>>pos;//玩家所在的位置
map<string,int>cnt;//玩家所占领的个数
intmain(){
	ios::sync_with_stdio(0); // 快读
	cin.tie(nullptr); // 快读
	cout.tie(nullptr); // 快读
	
	cin>>n>>m>>p; // 输入
	power.resize(p+1); // 初始化
	maps.resize(n+1,vector<string>(m+1,"__Empty")); // 初始化
	for(int i=1;i<=p;i++){ // 输入
		int x,y; // 输入
		string s; // 输入
		cin>>s>>x>>y; // 输入
		power[i]=s; // 输入
		maps[x][y]=s; // 输入
		pos[s]={x,y}; // 输入
		cnt[s]++; // 输入
	} // 输入
	int q;// 输入
	cin>>q;// 输入
	for(int i=1;i<=q;i++){ // 处理
		char c;// 输入
		string s;// 输入
		cin>>c>>s;// 输入
		auto[x,y]=pos[s]; // 处理
		if(x==-1&&y==-1){//玩家似了
			cout<<"unexistedempire.\n";//玩家似了
			continue;//玩家似了
		}//玩家似了
		if(c=='W')y--; //移动
		else if(c=='A')x--;//移动
		else if(c=='S')y++;//移动
		else if(c=='D')x++;//移动
		if(x<1||n<x||y<1||m<y){//出界力
			cout<<"outofbounds!\n";//出界力
			continue;//出界力
		}//出界力
		pos[s]={x,y};// 处理
		if(maps[x][y]!="__Empty"){//有人占领力
			if(maps[x][y]==s){//自己人
				cout<<"peaceful.";//自己人
			}else{//开打!
				string k=maps[x][y];//开打!
				if(cnt[s]>cnt[k]){ // S的领地>k
					cout<<s<<"wins!\n"; // S赢
					pos[k]={-1,-1}; // k死了
					maps[x][y]=s; // 这块地是S的
				}else if(cnt[s]<cnt[k]){// S的领地<k
					cout<<k<<"wins!\n"; // k赢
					pos[s]={-1,-1};// s死了
					maps[x][y]=k;// 这块地是k的
				}else{
					if(s>k){ // S的名字>k
						cout<<s<<"wins!\n"; // S赢
						pos[k]={-1,-1}; // k死了
						maps[x][y]=s;// 这块地是S的
					}else{// S的名字<k
						cout<<k<<"wins!\n";// k赢
						pos[s]={-1,-1};// s死了
						maps[x][y]=k;// 这块地是k的
					}
				}
			}
		}else{
			cout<<"vanquish!\n";//没人,这块地我要!
			maps[x][y]=s;// 这块地是S的
		}
	}
	return 0;//结束
}
原文