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具有一个 ...
随机推荐
- 【LG1975】[国家集训队]排队
[LG1975][国家集训队]排队 题面 洛谷 题解 又是一个偏序问题 显然\(CDQ\) 交换操作不好弄怎么办? 可以看成两次删除两次插入 排序问题要注意一下 代码 #include <ios ...
- Java:泛型擦除
https://docs.oracle.com/javase/tutorial/java/generics/erasure.html
- 「知识学习」二分图的最大匹配、完美匹配和匈牙利算法(HDU-2063)
定义 如果一个图\((E,V)\)的顶点集\(E\)能够被能够被分成两个不相交的集合\(X,Y\),且每一条边都恰连接\(X,Y\)中的各一个顶点,那么这个图就是一个二分图. 容易得知,它就是不含有奇 ...
- gitignore 文件生效办法
.gitignore 可以添加一些不加入git版本控制的文件 比如一些测试文件.因人而异的配置信息等等 .gitignore 文件展示如下 /.idea/target//.classpath /.pr ...
- 【MySQL解惑笔记】忘记MySQL数据库密码
破解MySQL密码 一.MySQL5.7.5之前 只要有系统root密码就可以破解: [root@host- ~]# vim /etc/my.cnf //在配置文件中加入如下内容 [mysqld] s ...
- C++ ifndef /define/ endif 作用和用法
ifndef/define/endif”主要目的是防止头文件的重复包含和编译 比如你有两个C文件,这两个C文件都include了同一个头文件.而编译时,这两个C文件要一同编译成一个可运行文件,于是问题 ...
- FPGA学习-VGA接口
一般FPGA开发板的VGA会向用户暴露两共五个种接口,第一种是时序信号,用于同步传输和显示:第二种是色彩信号,用于随着时序把色彩显示到显示器上 时序接口 行同步信号-用于指示一行内像素的显示 场同步信 ...
- Ubuntu—终端下重启与关机
重启命令 : 1.shutdown -r now 立刻重启 2.shutdown -r 10 过10分钟自动重启 3.shutdown -r 20:35 在时间为20:35 ...
- 259 [LeetCode] 3Sum Smaller 三数之和较小值
题目: Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 ...
- Java简单工厂模式
Java简单工厂模式 在阎宏博士的<JAVA与模式>一书中开头是这样描述简单工厂模式的:简单工厂模式是类的创建模式,又叫做静态工厂方法(Static Factory Method)模式.简 ...