Codeforces1023E Down or Right 【贪心】

题目分析:

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

代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 int n;
 5 
 6 int query(int x1,int y1,int x2,int y2){
 7     printf("? %d %d %d %d\n",x1,y1,x2,y2);
 8     fflush(stdout);
 9     char str[5];
10     scanf("%s",str);
11     if(str[0] == 'Y') return 1;
12     else return 0;
13     //int z; scanf("%d",&z);
14     //return z;
15 }
16 
17 stack<char> sta;
18 vector <char> vc;
19 void work(){
20     int x = 1,y = 1;
21     while(n-x+n-y > n-1){
22     int z = query(x,y+1,n,n);
23     if(z){vc.push_back('R');y++;}
24     else{vc.push_back('D');x++;}
25     }
26     int nx = n,ny = n;
27     while(nx != x || ny != y){
28     int z = query(1,1,nx-1,ny);
29     if(z){sta.push('D');nx--;}
30     else{sta.push('R');ny--;}
31     }
32     printf("! ");
33     for(int i=0;i<vc.size();i++) printf("%c",vc[i]);
34     while(!sta.empty()){printf("%c",sta.top());sta.pop();}
35 }
36 
37 int main(){
38     scanf("%d",&n);
39     work();
40     return 0;
41 }

 

posted @ 2018-08-20 20:16  menhera  阅读(211)  评论(0编辑  收藏  举报