1023E

题意:

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

思路:

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

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

  1. #include <algorithm>
  2. #include <iterator>
  3. #include <iostream>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <iomanip>
  7. #include <bitset>
  8. #include <cctype>
  9. #include <cstdio>
  10. #include <string>
  11. #include <vector>
  12. #include <cmath>
  13. #include <queue>
  14. #include <list>
  15. #include <map>
  16. #include <set>
  17. using namespace std;
  18. //#pragma GCC optimize(3)
  19. //#pragma comment(linker, "/STACK:102400000,102400000") //c++
  20. #define lson (l , mid , rt << 1)
  21. #define rson (mid + 1 , r , rt << 1 | 1)
  22. #define debug(x) cerr << #x << " = " << x << "\n";
  23. #define pb push_back
  24. #define pq priority_queue
  25.  
  26. typedef long long ll;
  27. typedef unsigned long long ull;
  28.  
  29. typedef pair<ll ,ll > pll;
  30. typedef pair<int ,int > pii;
  31. typedef pair<int,pii> p3;
  32.  
  33. //priority_queue<int> q;//这是一个大根堆q
  34. //priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
  35. #define fi first
  36. #define se second
  37. //#define endl '\n'
  38.  
  39. #define OKC ios::sync_with_stdio(false);cin.tie(0)
  40. #define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
  41. #define REP(i , j , k) for(int i = j ; i < k ; ++i)
  42. //priority_queue<int ,vector<int>, greater<int> >que;
  43.  
  44. const ll mos = 0x7FFFFFFF; //
  45. const ll nmos = 0x80000000; //-2147483648
  46. const int inf = 0x3f3f3f3f;
  47. const ll inff = 0x3f3f3f3f3f3f3f3f; //
  48. const int mod = 1e9+;
  49.  
  50. const double PI=acos(-1.0);
  51.  
  52. template<typename T>
  53. inline T read(T&x){
  54. x=;int f=;char ch=getchar();
  55. while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
  56. while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
  57. return x=f?-x:x;
  58. }
  59. // #define _DEBUG; //*//
  60. #ifdef _DEBUG
  61. freopen("input", "r", stdin);
  62. // freopen("output.txt", "w", stdout);
  63. #endif
  64. /*-----------------------showtime----------------------*/
  65. const int maxn = ;
  66. int vis[maxn];
  67. int n;
  68.  
  69. int get(int x,int y,int flag){
  70. char g[];
  71. if(flag)
  72. cout<<"? "<<x<<" "<<y<<" "<<n<<" "<<n<<endl;
  73. else cout<<"? "<<<<" "<<<<" "<<x<<" "<<y<<endl;
  74. cin>>g;
  75. if(g[] == 'Y')return ;
  76. else if(g[] == 'N') return ;
  77. return ;
  78. }
  79.  
  80. vector<int>up,down;
  81. void solve(){
  82. int x = , y = ;
  83. while(x+y<=n+){
  84. if(get(x,y,)){
  85. y++;up.pb();
  86. }
  87. else {
  88. x++;up.pb();
  89. }
  90. }
  91.  
  92. x = n-,y = n;
  93.  
  94. while(x+y>n){
  95. if(get(x,y,)){
  96. x--;down.pb();
  97. }
  98. else {
  99. y--;down.pb();
  100. }
  101. }
  102. }
  103.  
  104. int main(){
  105. cin>>n;
  106. solve();
  107.  
  108. string ans = "";
  109. for(int i=; i<up.size(); i++){
  110. int tmp = up[i];
  111. if(tmp==){
  112. ans+="D";
  113. }
  114. else ans += "R";
  115. }
  116.  
  117. for(int i=down.size() - ; i>=; i--){
  118. int tmp = down[i];
  119. if(tmp==){
  120. ans+="D";
  121. }
  122. else ans += "R";
  123. }
  124. cout<<"! "<<ans<<endl;
  125. return ;
  126. }

1023E

Codeforces Round #504 E - Down or Right 交互题的更多相关文章

  1. Codeforces Round #499 (Div. 2) D. Rocket_交互题_二分

    第一次作交互题,有点不习惯. 由于序列是循环的,我们可以将一半的机会用于判断当前是否是在说谎,另一半的机会用于二分的判断. 对于判断是否实在说谎,用1判断即可.因为不可能有比1还小的数. 本题虽然非常 ...

  2. Codeforces Round #504 E. Down or Right

    Codeforces Round #504 E. Down or Right 题目描述:交互题. 有一个\(n \times n\)的方阵,有一些格子是障碍,从\((1, 1)\)出发,只能向右向下走 ...

  3. Codeforces Round #504 D. Array Restoration

    Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...

  4. Codeforces 1023 A.Single Wildcard Pattern Matching-匹配字符 (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)

    Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Patter ...

  5. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  6. E - Down or Right Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    http://codeforces.com/contest/1023/problem/E 交互题 #include <cstdio> #include <cstdlib> #i ...

  7. Codeforces Round 504

    (交互题真神奇,,,我自己瞎写了一发目测样例都没过去就AC了...) (只出了两题的竟然没掉下蓝名真是可怕) A:我的代码太不美观了,放个同学的(因为我是c++63分的蒟蒻所以根本不知道那些函数怎么用 ...

  8. Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    考场上只做出了ABDE C都挂了... 题解: A 题解: 模拟 判断前面一段是否相同,后面一段是否相同,长度是否够(不能有重叠) Code: #include<stdio.h> #inc ...

  9. Codeforces Round #504:D. Array Restoration

    D. Array Restoration 题目链接:https://codeforces.com/contest/1023/problem/D 题意: 给出一个序列,现在要求对一个全为0的序列执行q次 ...

随机推荐

  1. java.sql.SQLException: Parameter index out of range (0 < 1 ).

    向SQL中传入数据是从1开始的!!! 从ResultSet中取数据也是从1开始的!

  2. Ubuntu下python安装mysqldb(驱动)

    最近在学习Django框架,需要使用到数据库,我使用的是mysql,跟java一样,需要安装驱动,这是驱动的下载网址http://sourceforge.net/projects/mysql-pyth ...

  3. Mac OS 安装mysqlclient 遇到的坑~

    最近在学习Python, 因为Django连接mysql 需要安装mysqlclient, 但Mac安装遇到各种问题,这里记录一下,避免以后再踩坑. 1.   正常情况下,安装mysqlclient ...

  4. 网站安装SSL证书成为影响SEO排名的重要因素之一

    百度谷歌先后发声明倡导站长们使用https链接,同样的网站,https站点要比http站点拥有更好的排名权重.https已经是网站SEO必须要考虑的环节之一了,而https的必要条件就是安装SSL证书 ...

  5. S2:.net

    1.net框架结构 主要包含公共语言运行时(CLR)和框架类库(.NET Framework 类库 ,FCL) 2.CLR 1.对于一个将要面向.NET平台进行开发的人来说,了解一下.NET平台的整 ...

  6. 【错误】【vscode】"'#' not expected here"

    今天使用vscode发现完整的代码报错了,但依然可以运行

  7. 【Java例题】2.3 计算银行存款本息

    3.计算银行存款本息. 用户输入存款金额money,存款期years和年利率rate, 根据公式: sum=money(1+rate)^years ,计算到期存款本息. 这里的"^" ...

  8. elk系列教程:docker中安装配置elk

    elasticSearch Docker安装elasticsearch: docker pull docker.io/elasticsearch:7.2.0 启动: docker run -p 920 ...

  9. [实践]redhat linux5.3安装tomcat

    1.安装准备 操作系统:RedHat 5 (自带apache2.2.3) 安装tomcat前首先要安装jdk: 查看系统是否安装了jdk或tomcat的命令: rpm -qa | grep java ...

  10. Java虚拟机(二)-对象创建

    这一篇大致说明一下,对象在Java堆中对象分配.内存布局以及访问定位 1.对象的创建 虚拟机在遇到一条new指令时,首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用,并且检查这个符号引 ...