CF995A Tesla
题目描述
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem.
Allen's future parking lot can be represented as a rectangle with 4 4 4 rows and n n n ( n≤50 n \le 50 n≤50 ) columns of rectangular spaces, each of which can contain at most one car at any time. He imagines having k k k ( k≤2n k \le 2n k≤2n ) cars in the grid, and all the cars are initially in the second and third rows. Each of the cars also has a different designated parking space in the first or fourth row. Allen has to put the cars into corresponding parking places.
Illustration to the first example.However, since Allen would never entrust his cars to anyone else, only one car can be moved at a time. He can drive a car from a space in any of the four cardinal directions to a neighboring empty space. Furthermore, Allen can only move one of his cars into a space on the first or fourth rows if it is the car's designated parking space.
Allen knows he will be a very busy man, and will only have time to move cars at most 20000 20000 20000 times before he realizes that moving cars is not worth his time. Help Allen determine if he should bother parking his cars or leave it to someone less important.
输入输出格式
输入格式:
The first line of the input contains two space-separated integers n n n and k k k ( 1≤n≤50 1 \le n \le 50 1≤n≤50 , 1≤k≤2n 1 \le k \le 2n 1≤k≤2n ), representing the number of columns and the number of cars, respectively.
The next four lines will contain n n n integers each between 0 0 0 and k k k inclusive, representing the initial state of the parking lot. The rows are numbered 1 1 1 to 4 4 4 from top to bottom and the columns are numbered 1 1 1 to n n n from left to right.
In the first and last line, an integer 1≤x≤k 1 \le x \le k 1≤x≤k represents a parking spot assigned to car x x x (you can only move this car to this place), while the integer 0 0 0 represents a empty space (you can't move any car to this place).
In the second and third line, an integer 1≤x≤k 1 \le x \le k 1≤x≤k represents initial position of car x x x , while the integer 0 0 0 represents an empty space (you can move any car to this place).
Each x x x between 1 1 1 and k k k appears exactly once in the second and third line, and exactly once in the first and fourth line.
输出格式:
If there is a sequence of moves that brings all of the cars to their parking spaces, with at most 20000 20000 20000 car moves, then print m m m , the number of moves, on the first line. On the following m m m lines, print the moves (one move per line) in the format i i i r r r c c c , which corresponds to Allen moving car i i i to the neighboring space at row r r r and column c c c .
If it is not possible for Allen to move all the cars to the correct spaces with at most 20000 20000 20000 car moves, print a single line with the integer −1 -1 −1 .
输入输出样例
4 5
1 2 0 4
1 2 0 4
5 0 0 3
0 5 0 3
6
1 1 1
2 1 2
4 1 4
3 4 4
5 3 2
5 4 2
1 2
1
2
1
2
-1
1 2
1
1
2
2
2
1 1 1
2 4 1
说明
In the first sample test case, all cars are in front of their spots except car 5 5 5 , which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most 20000 20000 20000 will be accepted.
In the second sample test case, there is only one column, and the cars are in the wrong order, so no cars can move and the task is impossible.
Solution:
本题居然是A题,然后思路确实是模拟,只不过太巧了。
我们固定一个方向移动所有的车子,比如顺时针,然后每次能进就进,否则就将其移动到空位上,然后重复这过程,不停绕圈就好了,可以证明即使某辆车反向偏离了终点,也最多只需要$2*50$步就能回来,所以最坏只要绕一圈能进的就进了。模拟此过程,设置一下步数限制,话说模拟题真的难写!
代码:
#include<bits/stdc++.h>
#define il inline
#define ll long long
#define For(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define Bor(i,a,b) for(int (i)=(b);(i)>=(a);(i)--)
using namespace std;
int n,k,a[][],tot;
struct node{
int id,x,y;
node(int a=,int b=,int c=){id=a,x=b,y=c;}
}ans[]; int main(){
scanf("%d%d",&n,&k);
For(i,,) For(j,,n) scanf("%d",&a[i][j]);
int nx=,ny=,cnt=,sum=;
while(cnt<=&&sum!=k){
int tx=nx,ty,gx,gy;
nx==?ty=ny+:ty=ny-;
if(ty>n) tx++,ty--;
if(ty<) tx--,ty++;
gy=ty;
tx==?gx=:gx=;
if(a[tx][ty]!=){
if(a[tx][ty]==a[gx][gy])ans[++tot]=node(a[tx][ty],gx,gy),sum++,a[tx][ty]=;
else if(!a[nx][ny]) ans[++tot]=node(a[tx][ty],nx,ny),swap(a[tx][ty],a[nx][ny]);
}
nx=tx,ny=ty;
cnt++;
}
if(sum==k) {
printf("%d\n",tot);
For(i,,tot) printf("%d %d %d\n",ans[i].id,ans[i].x,ans[i].y);
}
else puts("-1");
return ;
}
CF995A Tesla的更多相关文章
- Android开发笔记之《特斯拉-Tesla 代码分析》
转载请注明出处 一.反编译APK文件,查看包结构 // Android库,不多解释android.support // HttpClient 4.1 repackaged for Android // ...
- 基于Ubuntu14.04系统的nvidia tesla K40驱动和cuda 7.5安装笔记
基于Ubuntu14.04系统的nvidia tesla K40驱动和cuda 7.5安装笔记 飞翔的蜘蛛人 注1:本人新手,文章中不准确的地方,欢迎批评指正 注2:知识储备应达到Linux入门级水平 ...
- ubuntu14.04下的NVIDIA Tesla K80显卡驱动的安装教程
搞深度学习如何能够不与浑身是“核”的显卡打交道呢? 人工智能的兴起除了数据量的大量提升,算法的不断改进,计算能力的逐步提高,还离不开软件基础设施的逐步完善.当下的主流的深度学习工具软件无论是Caffe ...
- Tesla为什么要公开专利
这是今天在网上看到Tesla公司的专利墙图片,还是比较有视觉冲击力的,正好可以转来当配图. 业界先锋Tesla日前惊世骇俗地公开电动汽车专利,赢得如潮好评:不过大家都知道,对于西方科技公司,专利历来是 ...
- CUDA编程-(1)Tesla服务器Kepler架构和万年的HelloWorld
结合CUDA范例精解以及CUDA并行编程.由于正在学习CUDA,CUDA用的比较多,因此翻译一些个人认为重点的章节和句子,作为学习,程序将通过NVIDIA K40服务器得出结果.如果想通过本书进行CU ...
- 配有Tesla K40c的服务器新装Ubuntu16.04并安装CUDA8.0、Anaconda3、Matlab2016a、OPENCV3.1、CuDNN5.1、MXNet
注:本文原创,作者:Noah Zhang (http://www.cnblogs.com/noahzn/) 决定加入深度学习的大军,感谢导师给配了台新设备!第一次接触服务器并配置开发环境,整个过程中 ...
- 企业官网Web原型制作分享-Tesla
Tesla是汽车行业知名的奢华品牌,产品为纯电动汽车,知名度极高.此模板正是取自Tesla的官网,高端大图配上文字排版,彰显了汽车的奢华感觉. 本原型由国产Mockplus(原型工具)和iDoc(智能 ...
- 【转】Tesla autopilot 引起致命车祸
Tesla autopilot 引起致命车祸 好一段时间没关心 Tesla 了,今天才发现他们的 autopilot 终于引起了致命的车祸.这场 Model S 撞上18轮大卡车的车祸,发生于5月7号 ...
- 【转】Tesla Model X的车门设计问题
Tesla Model X的车门设计问题 Tesla即将推出的SUV(Model X),不但继承了以上提到的Model S的各种问题(触摸屏,门把,……),而且还制造了新的问题.Model X具有一个 ...
随机推荐
- clr via c#读书笔记四:call、callvirt
1.嵌套类,就是定义在类中的类:嵌套类可以访问外部类的方法.属性.字段而不管访问修饰符的限制,但是外部类只能够访问修饰符为public.internal的嵌套类的字段.方法.属性: 2.CLR如何调用 ...
- Chrome模拟平板调试
1. 按F12,打开开发者工具,右上角,点击红圈中的标志.然后在弹出的面板中点击'Emulation'. 2. 会看到左侧的四个选项卡 Device 设备.Screen 屏幕.User Agent ...
- Ruby学习系列一,基本认识
安装Ruby后,打开命令行,先来看下Ruby的版本. ruby -v ,如果看到类似 ruby 1.9.3p392.... ,说明我们的Ruby安装成功了. 然后我们输入 irb ,进入Ruby的交互 ...
- Nginx+Tomcat多站点访问默认主页问题-狒狒完美解决-Q9715234
<Engine name="Catalina" defaultHost="www.abc.com"> <Host name="www ...
- 180606-Linux下jdk中文乱码问题解决
文章链接:https://liuyueyi.github.io/hexblog/2018/06/06/180606-Linux下jdk中文乱码问题解决/ linux下jdk中文乱码问题解决 之前遇到过 ...
- Sysbench安装步骤及详情
Sysbench安装步骤及详情 Sysbench是压力测试工具,可以测试系统的CPU,内存,I/O等,也可以用于数据库的性能测试 Sysbench安装步骤: 安装具体分为Ubuntu16.04和Cen ...
- Linux命令应用大词典-第23章 进程和服务管理
23.1 ps:报告当前进程的快照 23.2 top:显示当前正在运行的进程 23.3 pgrep:按名称和其他属性查找进程 23.4 pidof:查找正在运行的进程的进程号 23.5 pstree: ...
- 【WXS全局对象】Date
属性: 名称 说明 Date.parse( [dateString] ) 解析一个日期时间字符串,并返回 1970/1/1 午夜距离该日期时间的毫秒数. Date.UTC(year,month,day ...
- Python基础 之 数据类型
数据类型 一.运算符 算数运算a = 10 * 10赋值运算a = a + 1 a+=1 布尔值:True 真 False 假 if True: pass while True: pass v = n ...
- Attention注意力机制介绍
什么是Attention机制 Attention机制通俗的讲就是把注意力集中放在重要的点上,而忽略其他不重要的因素.其中重要程度的判断取决于应用场景,拿个现实生活中的例子,比如1000个人眼中有100 ...