Hdu6048 Puzzle(2017多校第2场)
来源:互联网 发布:linux 宕机日志 编辑:程序博客网 时间:2024/06/11 19:54
Puzzle
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 469 Accepted Submission(s): 252
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
题意:给出一个n*m的方格,以及1到n*m-1的数字,一开始按照一定的规则(规则是每次选择剩余数中,第1个,第p+1个,第p*2+1个…,选完一轮后,去除选择的数,剩下的数继续按照这个规则来选)选择每个数,从上到下,从左到右填入方格中,最后留一个空格子。 方格中的空格子可以通过和相邻的数字交换位置来移动,问最后是否可以得到1到n*m-1这些数字按照从左到右从上到下的顺序放在方格中(右下角是空格)
解题思路:由题意得空格的横向移动:排列不发生改变,逆序对奇偶性不改变;空格的竖向移动:由于最后空格回到了右下角,即竖向交换的次数为偶数次,所以也必然不改变逆序对的奇偶性。又因为最后逆序数对必然为零,所以只需要看一开始的序列逆序数对是否为偶数即可。按题意生成原始序列可以发现每一轮后方比这个数小的数量是等差数列,公差为p-1,项数为(n-1)/p+1,所以不需要真正求出排列
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <string>#include <math.h>#include <time.h>#include <algorithm>#include <complex>#include <vector>#include <stack>#include <queue>#include <unordered_map>#include <set>using namespace std;#define LL long long#define mem(a,b) memset(a,b,sizeof a);const int inf=0x3f3f3f3f;const LL llinf=0x3f3f3f3f3f3f3f3f;const double pi=acos(-1.0);const double eps=1e-8;const LL mod=1e9+7;const int maxn=2010;int main(){ int T,m,n,p; for(~scanf("%d",&T);T--;) { scanf("%d%d%d",&n,&m,&p); int sum=m*n-1; int cnt=0; while(sum>=p) { int k=(sum-1)/p+1; cnt+=(p-1)*(k-1)*k/2; sum-=k; } if(cnt%2==0) printf("YES\n"); else printf("NO\n"); } return 0;}
阅读全文
0 0
- Hdu6048 Puzzle(2017多校第2场)
- HDU6048-Puzzle
- 2017多校2 1004 Puzzle
- 2017多校第二场 HDU 6048 Puzzle 逆序数,脑洞题,结论题
- 多校第六场1008---MU Puzzle
- HDU6053 TrickGCD(2017多校第2场)
- Hdu6046 hash(2017多校第2场)
- 2017多校第7场
- 2017多校第9场
- hdu 4662 MU Puzzle 多校第六场
- 2013 多校第六场 hdu 4662 MU Puzzle
- hdu 4662 MU Puzzle 13多校第六场
- OO Puzzle(2)
- C Puzzle解答(2)
- poj3678Katu Puzzle【2-SAT】
- njust1928 puzzle(2-sat)
- puzzle
- puzzle
- centos7搭建hadoop集群
- Map四种遍历方式以及增删改查方法总结
- 双向循环链表
- 通过反编译深入理解Java String及intern
- 重写PrineArea解决打印空白页问题
- Hdu6048 Puzzle(2017多校第2场)
- Android Tablayout+ViewPager使用及遇到的问题
- ffmpeg 返回错误数字含义
- notepad源码windows下编译教程(基于版本7.4.2)
- Android动态获取权限
- Qt之QTcpServer/QTcpSocket简单收发信息
- 信用是个什么玩意
- icepdf去水印方法
- Linux 发送get和post请求测试接口