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

Posted ckxkexing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #504 E - Down or Right 交互题相关的知识,希望对你有一定的参考价值。

1023E

题意:

  交互题。在一个有障碍地图中,问如何走才能从(1,1)走到(n,n),只能向右或者向左走。每次询问两个点,回复你这两个点能不能走通。

思路:

  只用最多2*n-2次询问。从(1,1),能向右走就向右走,不能就向下走,直到走到斜对角线上。从(n,n)出发,能向上走就向上走,不能就向左走,直到走到斜对角线上。

  因为保证有路,所以最后输出(1,1)出发的正向路径,加上从(n,n)出发的反向路径。

技术分享图片
#include <algorithm>
#include  <iterator>
#include  <iostream>
#include   <cstring>
#include   <cstdlib>
#include   <iomanip>
#include    <bitset>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include    <vector>
#include     <cmath>
#include     <queue>
#include      <list>
#include       <map>
#include       <set>
using namespace std;
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000")  //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "
";
#define pb push_back
#define pq priority_queue



typedef long long ll;
typedef unsigned long long ull;

typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3;

//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl ‘
‘

#define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A)  //用来压行
#define REP(i , j , k)  for(int i = j ; i <  k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que;

const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18
const int mod = 1e9+7;

const double PI=acos(-1.0);



template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<0||ch>9) f|=(ch==-),ch=getchar();
    while (ch>=0&&ch<=9) x=x*10+ch-0,ch=getchar();
    return x=f?-x:x;
}
// #define _DEBUG;         //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------showtime----------------------*/
            const int maxn = 550;
            int vis[maxn];
            int n;

            int get(int x,int y,int flag){
                char g[20];
                if(flag)
                    cout<<"? "<<x<<" "<<y<<" "<<n<<" "<<n<<endl;
                else cout<<"? "<<1<<" "<<1<<" "<<x<<" "<<y<<endl;
                cin>>g;
                if(g[0] == Y)return 1;
                else if(g[0] == N) return 0;
                return 0;
            }

            vector<int>up,down;
            void solve(){
                int x = 1, y = 2;
                while(x+y<=n+1){
                    if(get(x,y,1)){
                        y++;up.pb(1);
                    }
                    else {
                        x++;up.pb(0);
                    }
                }

                x = n-1,y = n;

                while(x+y>n){
                    if(get(x,y,0)){
                        x--;down.pb(0);
                    }
                    else {
                        y--;down.pb(1);
                    }
                }
            }

            
int main(){
            cin>>n;
            solve();

            string ans = "";
            for(int i=0; i<up.size(); i++){
                int tmp = up[i];
                if(tmp==0){
                    ans+="D";
                }
                else ans += "R";
            }

            for(int i=down.size() - 1; i>=0; i--){
                int tmp = down[i];
                if(tmp==0){
                    ans+="D";
                }
                else ans += "R";
            }
            cout<<"! "<<ans<<endl;
            return 0;
}
1023E

 

以上是关于Codeforces Round #504 E - Down or Right 交互题的主要内容,如果未能解决你的问题,请参考以下文章

$Codeforces; Round; 504; (Div.2)$

Codeforces Round #504 D. Array Restoration

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(示例代码