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\)为偶数 ...
随机推荐
- linux高性能服务器编程 (九) --I/O复用
第九章 I/O复用 I/O复用就是一个线程可以同时监听多个文件描述符,提高程序性能.虽然I/O复用可以同时监听多个文件描述符,但是它本身是阻塞的,如果多个文件描述符准备就绪,如果不采取措施它仍然是串行 ...
- dplyr
The d is for dataframes, the plyr is to evoke pliers. Pronounce however you like. dplyr包可用于处理 R 内部或者 ...
- node解析修改ngix配置文件
主要是通过nginx-conf这个工具. git地址:https://github.com/tmont/nginx-conf 具体用法: npm install -S nginx-conf 安装工具 ...
- C#控制台程序入口函数 Main(string[] args) 参数详解
学习C#编程最常见的示例程序是在控制台应用程序中输出Hello World! using System; namespace DemoMainArgs { class Program { static ...
- mybatis在sql中的CDATA区
示例 <if test="startTime != null"> <![CDATA[ AND rra.create_time >= #{startTime} ...
- 在 Windows 服务中托管 ASP.NET Core
众所周知,ASP.NET Core采用了和传统ASP.NET不同的托管和HTTP处理方式,即把服务器和托管环境完全解耦.ASP.NET Core内置了两个HTTP服务器实现,一个是基于libuv实现的 ...
- IIS服务器怎么查看网站日志
在做网站的优化以及网站安全的时候,分析网站的日志是非常重要的,但是公司的服务器是IIS的,以前弄的是linux的服务器,不知道该怎么弄,最终找到了解决办法. 1.iis默认是有日志的,在iislog下 ...
- [转]manjaro安装vmware虚拟机
全球领先的信息与通信解决方案供应商华为,近日面向全球ICT从业者,以及有兴趣掌握ICT相关知识的人士,免费推出其图形化网络仿真工具平台—eNSP.该平台通过对真实的网络设备的仿真模拟,帮助广大ICT从 ...
- Sequelize模糊查询
const Sequelize = require('sequelize'); const Op = Sequelize.Op; User.findAll({ raw: true, order: [ ...
- SpringBoot 上下文获取注入的Bean
import org.springframework.beans.BeansException; import org.springframework.context.ApplicationConte ...