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次 ...
随机推荐
- jQuery写toTop(回到顶部)效果
在通常的网站开发中,页面有时候会很长,尤其是一些电商网站,为了提高用户的体验效果,我们通常会增加一个回到顶部的按钮,这个按钮我们同城会使用fixed定位,将其定位在当前可视区域某一固定位置.这个效果用 ...
- TypeScript环境安装,以及配置idea开发环境
安装前准备 安装typescript需要用到npm管理工具,而npm是随同Node.js一起安装的包管理工具,所以要先安装Node 1.前往Node官网下载最新版安装包:http://nodejs.c ...
- 异步编程CompletableFuture实现高并发系统优化之请求合并
先说场景: 根据Redis官网介绍,单机版Redis的读写性能是12万/秒,批量处理可以达到70万/秒.不管是缓存或者是数据库,都有批量处理的功能.当我们的系统达到瓶颈的时候,我们考虑充分的压榨缓存和 ...
- oracle-11g2下载安装笔记
一.下载链接地址 http://download.oracle.com/otn/nt/oracle11g/112010/win64_11gR2_database_1of2.zip http://dow ...
- 死磕JVM之类中各部分的加载顺序
话不多说,直接上代码: 1.通过new创建对象实例: 2.当对象中含有静态方法,且调用时: -- 调用父类静态方法: 总结: * 类中静态资源首次加载的时间是类中静态资源第一次被调用的时候或者该类的对 ...
- Alfred Workflow
实用的 Alfred Workflow Alfred Workflow 介绍 alfred-pkgman-workflow 快速从各个软件仓库(maven, gradle 等等)中查找需要的软件包 A ...
- 单纯的xlistview
public class MainActivity extends AppCompatActivity implements XListView.IXListViewListener{ private ...
- 洛谷 P2024 [NOI2001]食物链
题意简述 有人用两种说法对这 N 个动物所构成的食物链关系进行描述: 1."1 X Y",表示 X 和 Y 是同类. 2."2 X Y",表示 X 吃 Y . ...
- Cocos Creator经典游戏制作之:信使(The Messenger)
版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...
- pickle 基础用法
def save_obj_to_file(path, target_obj): file = open(path,'wb') pickle.dump(target_obj) file.close() ...