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

Posted basasuya

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <assert.h>
#include <iomanip>
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
", 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
", l2, r2);
                for(int i = 0; i < (n+1 - l - r); ++i) ans2 += ‘R‘;
                break;
            }
            else {
                printf("? %d %d %d %d
", 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
", 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的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #504 E - Down or Right 交互题

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

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

Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Patter

Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) D. Array Restoration(示例代码

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