题目描述

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 .

输入输出样例

输入样例#1:

4 5
1 2 0 4
1 2 0 4
5 0 0 3
0 5 0 3
输出样例#1:

6
1 1 1
2 1 2
4 1 4
3 4 4
5 3 2
5 4 2
输入样例#2:

1 2
1
2
1
2
输出样例#2:

-1
输入样例#3:

1 2
1
1
2
2
输出样例#3:

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的更多相关文章

  1. Android开发笔记之《特斯拉-Tesla 代码分析》

    转载请注明出处 一.反编译APK文件,查看包结构 // Android库,不多解释android.support // HttpClient 4.1 repackaged for Android // ...

  2. 基于Ubuntu14.04系统的nvidia tesla K40驱动和cuda 7.5安装笔记

    基于Ubuntu14.04系统的nvidia tesla K40驱动和cuda 7.5安装笔记 飞翔的蜘蛛人 注1:本人新手,文章中不准确的地方,欢迎批评指正 注2:知识储备应达到Linux入门级水平 ...

  3. ubuntu14.04下的NVIDIA Tesla K80显卡驱动的安装教程

    搞深度学习如何能够不与浑身是“核”的显卡打交道呢? 人工智能的兴起除了数据量的大量提升,算法的不断改进,计算能力的逐步提高,还离不开软件基础设施的逐步完善.当下的主流的深度学习工具软件无论是Caffe ...

  4. Tesla为什么要公开专利

    这是今天在网上看到Tesla公司的专利墙图片,还是比较有视觉冲击力的,正好可以转来当配图. 业界先锋Tesla日前惊世骇俗地公开电动汽车专利,赢得如潮好评:不过大家都知道,对于西方科技公司,专利历来是 ...

  5. CUDA编程-(1)Tesla服务器Kepler架构和万年的HelloWorld

    结合CUDA范例精解以及CUDA并行编程.由于正在学习CUDA,CUDA用的比较多,因此翻译一些个人认为重点的章节和句子,作为学习,程序将通过NVIDIA K40服务器得出结果.如果想通过本书进行CU ...

  6. 配有Tesla K40c的服务器新装Ubuntu16.04并安装CUDA8.0、Anaconda3、Matlab2016a、OPENCV3.1、CuDNN5.1、MXNet

    注:本文原创,作者:Noah Zhang  (http://www.cnblogs.com/noahzn/) 决定加入深度学习的大军,感谢导师给配了台新设备!第一次接触服务器并配置开发环境,整个过程中 ...

  7. 企业官网Web原型制作分享-Tesla

    Tesla是汽车行业知名的奢华品牌,产品为纯电动汽车,知名度极高.此模板正是取自Tesla的官网,高端大图配上文字排版,彰显了汽车的奢华感觉. 本原型由国产Mockplus(原型工具)和iDoc(智能 ...

  8. 【转】Tesla autopilot 引起致命车祸

    Tesla autopilot 引起致命车祸 好一段时间没关心 Tesla 了,今天才发现他们的 autopilot 终于引起了致命的车祸.这场 Model S 撞上18轮大卡车的车祸,发生于5月7号 ...

  9. 【转】Tesla Model X的车门设计问题

    Tesla Model X的车门设计问题 Tesla即将推出的SUV(Model X),不但继承了以上提到的Model S的各种问题(触摸屏,门把,……),而且还制造了新的问题.Model X具有一个 ...

随机推荐

  1. Uber优步北京第四组奖励政策

    优步北京第四组: 定义为2015年7月20日至今激活的司机(以优步后台数据显示为准) 滴滴快车单单2.5倍,注册地址:http://www.udache.com/如何注册Uber司机(全国版最新最详细 ...

  2. Ubuntu 安装 搜狗输入法

    1.去下载搜狗输入法安装包: https://pinyin.sogou.com/linux/ 2.安装 sudo dpkg sougou****.deb 3.去设置 参考:https://blog.c ...

  3. spl_autoload_register()函数

    一.__autoload 这是一个自动加载函数,在PHP5中,当我们实例化一个未定义的类时,就会触发此函数.看下面例子: printit.class.php <?php class PRINTI ...

  4. SQL注入篇二------利用burp盲注,post注入,http头注入,利用burpsuit找注入点,宽字节注入

    1.布尔盲注burpsuit的使用 先自己构造好注入语句,利用burpsuit抓包,设置变量,查出想要的信息. 比如----查数据库名的ascii码得到数据库构造好语句 http://123.206. ...

  5. Siki_Unity_1-8_使用Unity开发2D游戏_PongGame

    Unity 1-8 使用Unity开发2D游戏 PongGame 任务1:演示 http://pan.baidu.com/s/1pKUHsev; up2i 任务2:案例介绍 创建PongGame,注意 ...

  6. go通过第三方库 mahonia gbk 转utf8

    go get github.com/axgle/mahonia dec := mahonia.NewDecoder("GBK")ret:=dec.ConvertString(res ...

  7. Java集合学习--集合总结

    一.ArrayList与Vector ArrayList与Vector很多地方大同小异,Vector现在已经基本不再使用.具体的管理如下:1.ArrayList与Vector都实现了List接口,底层 ...

  8. 41. Maximum Subarray

    Description Given an array of integers, find a contiguous subarray which has the largest sum. The su ...

  9. 【cookie接口】- jmeter - (请求提示no cookie)

    1.虽然 请求成功 响应码 200  ,但是  返回code 1  ,表示接口不成功 2.加入 空的cookie 管理器就可以了  返回 code 0 注意:状态码 200 只是表示请求是成功的 , ...

  10. sparkML原始数据转换成label-features方法

    数据1:kaggle-旧金山犯罪分类数据 格式如下: Dates,Category,Descript,DayOfWeek,PdDistrict,Resolution,Address,X,Y -- :: ...