HDU 6048 Puzzle(滑块游戏)
来源:互联网 发布:广西大学网络教育 编辑:程序博客网 时间:2024/06/05 08:02
Puzzle
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 92 Accepted Submission(s): 48
Problem Description
A Jigsaw puzzle contains N*M-1 pieces of jigsaws in a N rows*M columns rectangular board.Each jigsaw has a distinct number from 1 to N*M-1.Li is a naughty boy,he wants to arrange the board in his unique way.At the beginning,he picks all N*M-1 jigsaws out and put them on the table and then he will put them back to the board respecting the following steps:
1.Sorting all the remaining jigsaws on the table in ascending order.
2.Picking out the 1st ,the P+1 th ,the 2*P+1 th,......the n*P+1 th jigsaws and put them back to the blank area in the board one by one from the top row to the bottom row,from the left column to the right column.
3.if there are jigsaws remained on the table,back to step 1.
After he arranging the board,it’s obvious that there’s only one blank area located at the bottom-right corner.
Your task is to make the numbers on jigsaws sorted with every row and every column in ascending order(From left to right,top to bottom),and the blank area should be located at the bottom-right corner in the end.Each step you can move the blank area’s neighboring jigsaws(which share a common side with the blank area) towards the blank area.It’s really a difficult question,so you need to write a program to judge whether it is possible to complete the task.
1.Sorting all the remaining jigsaws on the table in ascending order.
2.Picking out the 1st ,the P+1 th ,the 2*P+1 th,......the n*P+1 th jigsaws and put them back to the blank area in the board one by one from the top row to the bottom row,from the left column to the right column.
3.if there are jigsaws remained on the table,back to step 1.
After he arranging the board,it’s obvious that there’s only one blank area located at the bottom-right corner.
Your task is to make the numbers on jigsaws sorted with every row and every column in ascending order(From left to right,top to bottom),and the blank area should be located at the bottom-right corner in the end.Each step you can move the blank area’s neighboring jigsaws(which share a common side with the blank area) towards the blank area.It’s really a difficult question,so you need to write a program to judge whether it is possible to complete the task.
Input
The first line contains an integer T(T<=100),which represents the number of test cases.
Following T lines,each line contains three integers N,M,P(2<=N,M<=1000;1<=P<=N*M-2).
Following T lines,each line contains three integers N,M,P(2<=N,M<=1000;1<=P<=N*M-2).
Output
For each test case,print “YES” in a separate line if it is possible to complete the task ,otherwise please print “NO”.
Sample Input
33 2 33 2 4999 999 1
Sample Output
YESNOYES
Source
2017 Multi-University Training Contest - Team 2
Recommend
liuyiding
题目大意:
给你一个N*M的矩阵,从上到下从左到右,依次填1, 2, 3,...右下角为空,每次可以把一个和空格有公共边的块和空格交换。按照特定方式打乱,问是否有解。
解题思路:
纯考察思维和找规律的一道题,最终结论就是按照第一行,第二行,第三行,。。。合并成一个一维数组,数组的逆序对数为偶数则有解,否则无解。证明比较长,官方题解写的很详细,这里就引用官方题解:
AC代码:
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <ctime>#include <vector>#include <queue>#include <stack>#include <deque>#include <string>#include <map>#include <set>#include <list>using namespace std;#define INF 0x3f3f3f3f#define LL long long#define fi first#define se second#define mem(a,b) memset((a),(b),sizeof(a))int N,M,P;int main(){ int T_T; scanf("%d",&T_T); while(T_T--) { scanf("%d%d%d",&N,&M,&P); int num=N*M-1, cnt=0;//剩下的数字数,逆序对数 while(num>P) { int n=(num-1)/P+1;//这一轮拿出的数字 cnt+=n*(n-1)/2*(P-1);//逆序对数 num-=n; } puts(cnt&1?"NO":"YES"); } return 0;}
阅读全文
2 0
- HDU 6048 Puzzle(滑块游戏)
- Puzzle(HDU 6048)
- HDU 6048 Puzzle(机智)
- HDU-6048 Puzzle(思维题)
- HDU 6048 Puzzle(逆序数+等差数列)
- hdu 6048 Puzzle(规律+逆序对)
- HDU 6048 Puzzle
- hdu 6048puzzle (逆序对)
- Puzzle HDU
- hdu 6048 Puzzle 思维(8数码问题
- 【HDU 6048 Puzzle】 逆序对 & 思维
- hdu 4708 Rotation Lock Puzzle(模拟)
- HDU 1097 A hard puzzle(规律)
- HDU 4021 24 Puzzle (拼图)
- HDU 1098 Ignatius's puzzle(数论)
- hdu 1098Ignatius's puzzle(math)
- hdu 4662 MU Puzzle(水)
- HDU 4662 MU Puzzle(找规律)
- UML类图各符号意义
- Ubuntu17.04 安装搜狗中文输入法
- 修改Ubuntu14.04虚拟机MTU值
- Fire! UVA-11624
- 微服务:Spring Boot第二篇——运行原理和HelloWorld
- HDU 6048 Puzzle(滑块游戏)
- 第三方登录 验证码 日夜间模式
- 图片样式,辅助类样式
- Spring(13)——PropertyPlaceholderConfigurer
- iOS UIGestureRecognizer(手势操作)~demo
- 一个简单的爬虫程序(爬取百度百科关于python的一千个页面)
- springcloud读取git上的配置文件
- Django models中的meta选项
- hdu6055_Regular polygon_暴力枚举