Codeforces1023E Down or Right 【贪心】

时间:2021-06-05 00:22:30

题目分析:

从起点开始询问终点连通性,优先右走。从终点开始询问起点连通性,优先上走。

代码:

 #include<bits/stdc++.h>
using namespace std; int n; int query(int x1,int y1,int x2,int y2){
printf("? %d %d %d %d\n",x1,y1,x2,y2);
fflush(stdout);
char str[];
scanf("%s",str);
if(str[] == 'Y') return ;
else return ;
//int z; scanf("%d",&z);
//return z;
} stack<char> sta;
vector <char> vc;
void work(){
int x = ,y = ;
while(n-x+n-y > n-){
int z = query(x,y+,n,n);
if(z){vc.push_back('R');y++;}
else{vc.push_back('D');x++;}
}
int nx = n,ny = n;
while(nx != x || ny != y){
int z = query(,,nx-,ny);
if(z){sta.push('D');nx--;}
else{sta.push('R');ny--;}
}
printf("! ");
for(int i=;i<vc.size();i++) printf("%c",vc[i]);
while(!sta.empty()){printf("%c",sta.top());sta.pop();}
} int main(){
scanf("%d",&n);
work();
return ;
}