• 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
    ..#.......
    ...#......
    ......#...
    .#.......#
    ..........
    .........#
    .......#..
    .......#..
    ..........
    ..........
    
    */
    
  • 相关阅读:
    Spring中依赖注入的四种方式
    使用 EasyMock 更轻松地进行测试
    HDU2196 Computer(树形DP)
    BZOJ2125: 最短路(圆方树)
    虚树入门
    BZOJ2286: [Sdoi2011]消耗战(虚树/树形DP)
    Codeforces Round #487 (Div. 2)
    Educational Codeforces Round 45 (Rated for Div. 2)
    BZOJ3675: [Apio2014]序列分割(斜率优化)
    BZOJ2761: [JLOI2011]不重复数字(map)
  • 原文地址:https://www.cnblogs.com/Basasuya/p/9572232.html
Copyright © 2020-2023  润新知