日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/5/22 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 << "\n"; #define pb push_back #define pq priority_queuetypedef 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; //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

?

轉載于:https://www.cnblogs.com/ckxkexing/p/9497121.html

總結

以上是生活随笔為你收集整理的Codeforces Round #504 E - Down or Right 交互题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。