zoukankan      html  css  js  c++  java
  • 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
    ..#.......
    ...#......
    ......#...
    .#.......#
    ..........
    .........#
    .......#..
    .......#..
    ..........
    ..........
    
    */
    
  • 相关阅读:
    [javaSE] 网络编程(浏览器客户端-自定义服务端)
    [javaSE] 网络编程(URLConnection)
    [javaSE] 网络编程(URL)
    [javaSE] IO流(FIle对象递归文件列表)
    tcping 与 telnet命令粗略使用
    让mysql监听ipv4
    shell脚本[] [[]] -n -z 的含义解析
    ansible的主机的默认配置部分
    MySQL备份与还原
    gunicorn 简介
  • 原文地址:https://www.cnblogs.com/Basasuya/p/9572232.html
Copyright © 2011-2022 走看看