Robot Arms AtCoder - 4432 (构造)
大意: 给定平面上$n$个点$(x_i,y_i)$. 要求构造一个序列$d$, $d_i$表示每步走的距离, 再构造$n$个命令串, 要求从原点出发按照第$i$个命令走, 走完恰好到达$(x_i,y_i)$.
构造完全没思路, 看了题解才懂
首先若存在两个点的$x+y$的奇偶性不同, 那么显然无解.
其余情况假设$x+y$为奇数, 那么构造$d=1,2,4,8,16,...$, 然后命令可以贪心构造出来.
若$x+y$为偶数, $d$中添加一个$1$, 变为奇数的情况即可.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e5+10;
int n, a[N], b[N], d[N];
char s[N]; int main() {
scanf("%d", &n);
int c[2]{};
REP(i,1,n) {
scanf("%d%d",a+i,b+i);
++c[a[i]+b[i]&1];
}
if (c[0]!=n&&c[1]!=n) return puts("-1"),0;
printf("%d\n",31+!!c[0]);
REP(i,0,30) printf("%d ", 1<<i);
if (c[0]) printf("%d ", 1);
hr;
REP(i,1,n) {
int x = a[i], y = b[i];
if (c[0]) --x, s[31] = 'R';
int f = 0;
PER(i,0,30) {
if (abs(x)<abs(y)) swap(x,y), f^=1;
if (x>0) x-=1<<i,s[i]="RU"[f];
else x+=1<<i,s[i]="LD"[f];
}
puts(s);
}
}
Robot Arms AtCoder - 4432 (构造)的更多相关文章
- AtCoder Regular Contest 103 Problem D Robot Arms (构造)
题目链接 Problem D 给定$n$个坐标,然后让你构造一个长度为$m$的序列, 然后给每个坐标规定一个长度为$m$的序列,ULRD中的一个,意思是走的方向, 每次从原点出发按照这个序列方向,每 ...
- [Atcoder ARC103D]Robot Arms
题目大意:平面上有$n$个点,要求你构造$m$条边(满足$m\leqslant40$),使得可以从原点到达给定的$n$个点(边必须平行于坐标轴).并要求输出每一条边的方向,每条边必须都使用,无解输出$ ...
- 「ARC103D」Robot Arms「构造」
题意 给定\(n\)个点,你需要找到一个合适的\(m\)和\(d_1,d_2,...,d_m\),使得从原点出发每次向四个方向的某一个走\(d_i\)个单位,最终到达\((x_t, y_t)\).输出 ...
- 【CF1073C】Vasya and Robot(二分,构造)
题意:给定长为n的机器人行走路线,每个字符代表上下左右走,可以更改将一些字符改成另外三个字符,定义花费为更改的下标max-min+1, 问从(0,0)走到(X,Y)的最小花费,无解输出-1 n< ...
- Tr/ee AtCoder - 4433 (构造)
大意: 给定长$n$的字符串$s$, 要求构造一棵树, 满足若第$i$个字符为$1$, 那么可以删一条边, 得到一个大小为$i$的连通块. 若为$0$则表示不存在一条边删去后得到大小为$i$的连通块. ...
- [atARC103D]Robot Arms
合法的必要条件是每个点两维坐标和奇偶性相同,同时这也是充分条件 令$d_{i}=\{2^{0},2^{1},...,2^{m-1}\}$,归纳其可以走到任意满足$|x|+|y|<2^{m}$的$ ...
- 【AtCoder】ARC103
C - //// 为了防止一些多余的判断,我选择直接记录每个数的个数,然后枚举第一个数,找第一个数之外第二个数改变最少的情况下应该选什么 代码 #include <bits/stdc++.h&g ...
- AtCoder刷题记录
构造题都是神仙题 /kk ARC066C Addition and Subtraction Hard 首先要发现两个性质: 加号右边不会有括号:显然,有括号也可以被删去,答案不变. \(op_i\)和 ...
- AtCoder | ARC103 | 瞎讲报告
目录 ARC 103 A.//// B.Robot Arms C.Tr/ee D.Distance Sums ARC 103 窝是传送门QwQ A.//// 题意 : 给你\(n\)(\(n\)为偶数 ...
随机推荐
- 系统权限远程线程注入到Explorer.exe
目录 提升为系统权限,注入到explorer中 一丶简介 二丶注入效果图 提升为系统权限,注入到explorer中 一丶简介 我们上一面说了系统服务拥有系统权限.并且拥有system权限.还尝试启动了 ...
- nginx.conf 配置解析之文件结构
nginx.conf配置文件结构如下: ...... #主要定义nginx的全局配置 events{ #events(事件)块:主要配置网络连接相关 } http{ #http块:代理缓存和日志定义绝 ...
- shell 换行与不换行
test.sh: echo -e "hello w\norld!"echo -e "hello w\c"echo "orld!" 输出 bo ...
- AMPPZ2014 The Captain
传送门 BZOJdown Solution 比较妙,考虑按照给出的式子,只有\(x\)相邻或者\(y\)相邻的才会走,不然一定会走到相邻的再走\(x\)或\(y\),所以直接排序两边然后最短路即可. ...
- 年轻人的第一个自定义 Spring Boot Starter!
陆陆续续,零零散散,栈长已经写了几十篇 Spring Boot 系列文章了,其中有介绍到 Spring Boot Starters 启动器,使用的.介绍的都是第三方的 Starters ,那如何开发一 ...
- Ubuntu 17.10安装VirtualBox 5.2.2 及相关问题解决
link:https://www.linuxidc.com/Linux/2017-11/148870.htm sudo apt update && sudo apt upgrade s ...
- java和vue2.0
1 java中的el表达式${对象.属性}和vue中的双向数据绑定{{mode.xx}}感觉有点类似 2 java中 request.setAttribute("hots", l ...
- Win10登陆界面卡住,进去后无法打开网络相关的设置,谷歌浏览器无法上网
今天Win10抽风,进入登录页面输入用户名和密码之后,大约过了10分钟才进入桌面.重启后仍然如此. 经过调查,问题主要出在网络相关模块上,网络无法正常初始化,导致登录一直卡在网络初始化上. 解决方法如 ...
- RequireJS - 快速指南
原文: https://www.tutorialspoint.com/requirejs/requirejs_quick_guide.htm RequireJS - 概述 RequireJS是一个Ja ...
- SQL Server 2008 R2 安装 下载
[参考]https://www.aiweibk.com/6697.html winrm 服务未启动,需要先配置.以管理员身份启动 cmd,执行 winrm quickconfig 命令. 微信截图_2 ...