Codeforces Round #504 E - Down or Right 交互题
题意:
交互题。在一个有障碍地图中,问如何走才能从(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
Codeforces Round #504 E - Down or Right 交互题的更多相关文章
- Codeforces Round #499 (Div. 2) D. Rocket_交互题_二分
第一次作交互题,有点不习惯. 由于序列是循环的,我们可以将一半的机会用于判断当前是否是在说谎,另一半的机会用于二分的判断. 对于判断是否实在说谎,用1判断即可.因为不可能有比1还小的数. 本题虽然非常 ...
- Codeforces Round #504 E. Down or Right
Codeforces Round #504 E. Down or Right 题目描述:交互题. 有一个\(n \times n\)的方阵,有一些格子是障碍,从\((1, 1)\)出发,只能向右向下走 ...
- Codeforces Round #504 D. Array Restoration
Codeforces Round #504 D. Array Restoration 题目描述:有一个长度为\(n\)的序列\(a\),有\(q\)次操作,第\(i\)次选择一个区间,将区间里的数全部 ...
- 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 ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- 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 ...
- Codeforces Round 504
(交互题真神奇,,,我自己瞎写了一发目测样例都没过去就AC了...) (只出了两题的竟然没掉下蓝名真是可怕) A:我的代码太不美观了,放个同学的(因为我是c++63分的蒟蒻所以根本不知道那些函数怎么用 ...
- Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
考场上只做出了ABDE C都挂了... 题解: A 题解: 模拟 判断前面一段是否相同,后面一段是否相同,长度是否够(不能有重叠) Code: #include<stdio.h> #inc ...
- Codeforces Round #504:D. Array Restoration
D. Array Restoration 题目链接:https://codeforces.com/contest/1023/problem/D 题意: 给出一个序列,现在要求对一个全为0的序列执行q次 ...
随机推荐
- java.sql.SQLException: Parameter index out of range (0 < 1 ).
向SQL中传入数据是从1开始的!!! 从ResultSet中取数据也是从1开始的!
- Ubuntu下python安装mysqldb(驱动)
最近在学习Django框架,需要使用到数据库,我使用的是mysql,跟java一样,需要安装驱动,这是驱动的下载网址http://sourceforge.net/projects/mysql-pyth ...
- Mac OS 安装mysqlclient 遇到的坑~
最近在学习Python, 因为Django连接mysql 需要安装mysqlclient, 但Mac安装遇到各种问题,这里记录一下,避免以后再踩坑. 1. 正常情况下,安装mysqlclient ...
- 网站安装SSL证书成为影响SEO排名的重要因素之一
百度谷歌先后发声明倡导站长们使用https链接,同样的网站,https站点要比http站点拥有更好的排名权重.https已经是网站SEO必须要考虑的环节之一了,而https的必要条件就是安装SSL证书 ...
- S2:.net
1.net框架结构 主要包含公共语言运行时(CLR)和框架类库(.NET Framework 类库 ,FCL) 2.CLR 1.对于一个将要面向.NET平台进行开发的人来说,了解一下.NET平台的整 ...
- 【错误】【vscode】"'#' not expected here"
今天使用vscode发现完整的代码报错了,但依然可以运行
- 【Java例题】2.3 计算银行存款本息
3.计算银行存款本息. 用户输入存款金额money,存款期years和年利率rate, 根据公式: sum=money(1+rate)^years ,计算到期存款本息. 这里的"^" ...
- elk系列教程:docker中安装配置elk
elasticSearch Docker安装elasticsearch: docker pull docker.io/elasticsearch:7.2.0 启动: docker run -p 920 ...
- [实践]redhat linux5.3安装tomcat
1.安装准备 操作系统:RedHat 5 (自带apache2.2.3) 安装tomcat前首先要安装jdk: 查看系统是否安装了jdk或tomcat的命令: rpm -qa | grep java ...
- Java虚拟机(二)-对象创建
这一篇大致说明一下,对象在Java堆中对象分配.内存布局以及访问定位 1.对象的创建 虚拟机在遇到一条new指令时,首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用,并且检查这个符号引 ...