Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) E. Down or Right

从(1,1,n,n)每次只变一个坐标,进行询问。
如果问到对角线有距离限制,
再从(1,1,n/2,n/2)询问到(n/2,n/2,n,n)

记住前半部分贪心忘上走,后本部分贪心往右走
因为最后的路线可能有多条
所以这样走的话一定能找到一条对角线在右上角的路线

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;


string ans, ans2;
char seq[5];
int main() {
    int n;
    
    while(~scanf("%d", &n)) {
        int l = n, r = n;
        ans.clear();
        while(1) {
            printf("? %d %d %d %d\n", 1, 1, l-1, r); fflush(stdout);
            scanf("%s", seq);
            if(seq[0] == 'Y') {
                l --;
                ans += 'D';
            } else {
                r --;
                ans += 'R';
            }

            if(l + r == n + 1) break;
        }

        int cnt = ans.length() - 1;
        
        int l2 = l; int r2 = r;
        l = 1; r = 1;
        int endL = l2;
        ans2.clear();
        while(1) {
            assert(cnt >= 0);
            if(ans[cnt] == 'D') l2 ++;
            else r2 ++;
            cnt --;
        
            if(l == endL) {
            //    printf("%d %d\n", l2, r2);
                for(int i = 0; i < (n+1 - l - r); ++i) ans2 += 'R';
                break;
            }
            else {
                printf("? %d %d %d %d\n", l, r+1, l2, r2); fflush(stdout);
            }
            scanf("%s", seq);
            if(seq[0] == 'N') {
                l ++;
                ans2 += 'D';
            } else {
                r ++;
                ans2 += 'R';
            } 
            if(l + r == n+1) break;
        }

        reverse(ans.begin(), ans.end());
        string ans3 = ans2 + ans;
        printf("! %s\n", ans3.c_str()); 
        fflush(stdout);
    }
    return 0;
}

/*

10
..#.......
...#......
......#...
.#.......#
..........
.........#
.......#..
.......#..
..........
..........

*/

你可能感兴趣的:(Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) E. Down or Right)