社区讨论
20pts,纯模拟,玄关。
P9804 [POI 2022/2023 R1] kol参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mhj07hcw
- 此快照首次捕获于
- 2025/11/03 18:35 4 个月前
- 此快照最后确认于
- 2025/11/03 18:35 4 个月前
代码:
CPP#include<bits/stdc++.h>
using namespace std;
#define int long long
int m,p,n,cnt=0;
struct Node{
int w,k,c;
}arr[1000005];
int mpshe[2005][2005],mpshi[2005][2005];
int she[1000005];
signed main(){
cin>>m>>p>>n;
for(int i=0;i<=m;i++){
for(int j=0;j<=m;j++){
mpshe[i][j]=-1;
mpshi[i][j]=-1;
}
}
for(int i=1;i<=p;i++){
cin>>arr[i].w>>arr[i].k>>arr[i].c;
mpshi[arr[i].w][arr[i].k]=arr[i].c;
}
mpshe[1][1]=0;
she[cnt]=0;
pair<int,int> be={1,1},en={1,1};
int t=0;
while(n--){
char op;
cin>>op;
if(op=='G'){
en.first--;
mpshe[en.first][en.second]=++t;
if(mpshi[en.first][en.second]==-1){
pair<int,int> z=be;
if(mpshe[be.first-1][be.second]==mpshe[be.first][be.second]+1){
be.first--;
}else if(mpshe[be.first][be.second-1]==mpshe[be.first][be.second]+1){
be.second--;
}else if(mpshe[be.first+1][be.second]==mpshe[be.first][be.second]+1){
be.first++;
}else{
be.second++;
}
mpshe[z.first][z.second]=-1;
}else{
she[++cnt]=mpshi[en.first][en.second];
mpshi[en.first][en.second]=-1;
}
}else if(op=='D'){
en.first++;
mpshe[en.first][en.second]=++t;
if(mpshi[en.first][en.second]==-1){
pair<int,int> z=be;
if(mpshe[be.first-1][be.second]==mpshe[be.first][be.second]+1){
be.first--;
}else if(mpshe[be.first][be.second-1]==mpshe[be.first][be.second]+1){
be.second--;
}else if(mpshe[be.first+1][be.second]==mpshe[be.first][be.second]+1){
be.first++;
}else{
be.second++;
}
mpshe[z.first][z.second]=-1;
}else{
she[++cnt]=mpshi[en.first][en.second];
mpshi[en.first][en.second]=-1;
}
}else if(op=='L'){
en.second--;
mpshe[en.first][en.second]=++t;
if(mpshi[en.first][en.second]==-1){
pair<int,int> z=be;
if(mpshe[be.first-1][be.second]==mpshe[be.first][be.second]+1){
be.first--;
}else if(mpshe[be.first][be.second-1]==mpshe[be.first][be.second]+1){
be.second--;
}else if(mpshe[be.first+1][be.second]==mpshe[be.first][be.second]+1){
be.first++;
}else{
be.second++;
}
mpshe[z.first][z.second]=-1;
}else{
she[++cnt]=mpshi[en.first][en.second];
mpshi[en.first][en.second]=-1;
}
}else if(op=='P'){
en.second++;
mpshe[en.first][en.second]=++t;
if(mpshi[en.first][en.second]==-1){
pair<int,int> z=be;
if(mpshe[be.first-1][be.second]==mpshe[be.first][be.second]+1){
be.first--;
}else if(mpshe[be.first][be.second-1]==mpshe[be.first][be.second]+1){
be.second--;
}else if(mpshe[be.first+1][be.second]==mpshe[be.first][be.second]+1){
be.first++;
}else{
be.second++;
}
mpshe[z.first][z.second]=-1;
}else{
she[++cnt]=mpshi[en.first][en.second];
mpshi[en.first][en.second]=-1;
}
}else{
int x,y;
cin>>x>>y;
if(mpshe[x][y]==-1){
cout<<-1<<'\n';
continue;
}
cout<<she[mpshe[x][y]-mpshe[be.first][be.second]]<<'\n';
}
}
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...