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具有一个 ...
随机推荐
- OpenCV 3.2 Viz 3D可视化
该可视化模块提供了坐标系变化,3D动画等功能 最简单的显示坐标系 viz::Viz3d window("window"); window.showWidget("Coor ...
- Python常用函数--return 语句
在Python教程中return 语句是函数中常用的一个语句.return 语句用于从函数中返回,也就是中断函数.我们也可以选择在中断函数时从函数中返回一个值.案例(保存为 function_retu ...
- JS里点击事件判断是否 触发了节点 和给标签添加class属性
$("#activityType").click(function(e){ if(e.target==$("#bb")[0]){ var bb=document ...
- 利用nohup后台运行jar文件包程序
Linux 运行jar包命令如下: 方式一: java -jar XXX.jar特点:当前ssh窗口被锁定,可按CTRL + C打断程序运行,或直接关闭窗口,程序退出 那如何让窗口不锁定? 方式二 j ...
- 技本功丨知否知否,Redux源码竟如此意味深长(下集)
上集回顾 Redux是如何使用的?首先再来回顾一下这个使用demo(谁让这段代码完整地展示了redux的使用) 如果有小伙伴对这段代码不是很理解的话,建议先去学习Redux的使用再来看这篇源码,这样更 ...
- CodeForces 908C. New Year and Curling 解题报告 Java
1. 思路 这题实际上是个几何问题——两个外相切的圆,由勾股定理,他们的纵坐标有以下的规律: 则有$$y_{n+1} = y_{n} + \sqrt{(2r)^2 - (x_{n} - x_{n+1} ...
- Python3 小工具-MAC泛洪
from scapy.all import * import optparse def attack(interface): pkt=Ether(src=RandMAC(),dst=RandMAC() ...
- js经典试题之ES6
js经典试题之ES6 1:在ECMAScript6 中,Promise的状态 答案:pending resolved(fulfilled) rejected 解析: Promise对象只有三种状态: ...
- 浏览器中event.srcElement和event.target的兼容性问题
在IE下,event对象有srcElement属性,但是没有target属性:Firefox下,even对象有target属性,但是没有srcElement属性.. 解决方法:使用obj(obj = ...
- iOS开发NS_ENUM和NS_OPTIONS区别
OC里枚举的两种类型.NS_ENUM和NS_OPTIONS本质上是一样的都是枚举. typedef NS_ENUM(NSInteger, UIViewAnimationTransition) { UI ...