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次 ...
随机推荐
- rem的基准字体大小的设置
1.移动端 UI 给的设计稿通常是640px.720px.750px的宽度,但是我们要做适配,兼容不同的终端,rem布局是比较常用的一种方式,比较关键的是确定根节点的字体大小. 这里以640px为例, ...
- Linux升级GCC
升级原因 测试需要使用DOClever,下载了最新的node8.11,运行node 时候报错 [root@app_test bin]# node www module.js:681 return pr ...
- UE4 代理 BindRaw和BindUObject
代理允许您在C++对象上以通用的但类型安全的方式调用成员函数.通过使用代理,可以将其动态地绑定到任何对象的成员函数上,然后在该对象上调用函数,即时调用者不知道该对象的类型也没关系. 任何时候都应该通过 ...
- C++实现反射
之前碰到过一个问题,C++中如何通过一个字符串生成一个类. C++是不支持通过类名称字符串”ClassXX”来生成对象的,也就是说我们可以使用 new ClassXX 来生成对象,但是不能通过 new ...
- 非UI线程更新界面
package com.caterSys.Thread; import java.text.SimpleDateFormat; import java.util.Date; import org.ec ...
- 全开源C++ DirectUI 界面库SOUI 3.0更新
从2019.5.22开始,SOUI版本号更新到2.9.0.2,后面开始准备3.0的开发,历时近3个月,现在3.0的主要工作基本完成. 为了便于大家区别2.x,3.0启用了新的代码仓库:https:// ...
- 如何创建Github创库
重点:利用Markdown语言写简单的日常使用的文本 基础写作和语法格式 本篇文章的内容来源于Github的基础写作帮助.如果在观看时有什么问题,可以直接查阅源文件.另外需要说明的是Git对Markd ...
- leetcode 29 两数相除
问题描述 给定两个整数,被除数 dividend 和除数 divisor.将两数相除,要求不使用乘法.除法和 mod 运算符. 返回被除数 dividend 除以除数 divisor 得到的商. 示例 ...
- mybatis学习笔记(一)
mybatis学习笔记 mybatis简介 Mybatis 开源免费框架.原名叫iBatis,2010在googlecode,2013年迁移到 github 作用: 数据访问层框架,底层对JDBC进行 ...
- Java——标准异常
Throwable这个java类被用来表示任何可以作为异常被抛出的类,Throwable可以分为两种类型,Error用来表示编译时和系统错误,Exception是可以被抛出的基本类型. 1.Runti ...