题意:
交互题。在一个有障碍地图中,问如何走才能从(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 << "\n";
#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 '\n' #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; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+; const double PI=acos(-1.0); template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',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 = ;
int vis[maxn];
int n; int get(int x,int y,int flag){
char g[];
if(flag)
cout<<"? "<<x<<" "<<y<<" "<<n<<" "<<n<<endl;
else cout<<"? "<<<<" "<<<<" "<<x<<" "<<y<<endl;
cin>>g;
if(g[] == 'Y')return ;
else if(g[] == 'N') return ;
return ;
} vector<int>up,down;
void solve(){
int x = , y = ;
while(x+y<=n+){
if(get(x,y,)){
y++;up.pb();
}
else {
x++;up.pb();
}
} x = n-,y = n; while(x+y>n){
if(get(x,y,)){
x--;down.pb();
}
else {
y--;down.pb();
}
}
} int main(){
cin>>n;
solve(); string ans = "";
for(int i=; i<up.size(); i++){
int tmp = up[i];
if(tmp==){
ans+="D";
}
else ans += "R";
} for(int i=down.size() - ; i>=; i--){
int tmp = down[i];
if(tmp==){
ans+="D";
}
else ans += "R";
}
cout<<"! "<<ans<<endl;
return ;
}
1023E