hdu 6048 Puzzle(规律+逆序对)
来源:互联网 发布:java系统源码下载 编辑:程序博客网 时间:2024/05/17 01:58
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
题意:一个
题解:
结论一:相邻的两个数字块交换位置改变序列逆序对数量的奇偶性。
结论二:白块左右移动不会改变逆序对的数量。
结论三:白块上下移动最终不会改变逆序对数量的奇偶性。因为白块每向上或向下移动一位相当于对应的数字块向下或向上移动
结论四:任何规模的拼图最终一定会成为只有右下角
结论五:由以上结论可知,任何局面一定可以转化为右下角
求逆序对时,可以累加每个数字后面比它小的数字的个数,即累加每个数字对逆序对的贡献。设当前轮剩余的数字数量为
#include <cstdio>#include <map>#include <cstring>#include <algorithm>#include<iostream>#include<cmath>#define ll long longusing namespace std;int n, m, p;int main() { int t, temp, num, Count; scanf("%d", &t); while(t--) { Count = 0; scanf("%d%d%d", &n, &m, &p); num = n *m - 1; while(num > p) { temp = (num-1) / p + 1; Count += temp*(temp-1)/2*(p-1); num -= temp; } if(Count & 1) printf("NO\n"); else printf("YES\n"); }}
阅读全文
0 0
- hdu 6048 Puzzle(规律+逆序对)
- hdu 6048puzzle (逆序对)
- 【HDU 6048 Puzzle】 逆序对 & 思维
- HDU 6048 Puzzle(逆序数+等差数列)
- HDU 6048 Puzzle 逆序对 计数 发现基本操作
- HDU 1097 A hard puzzle(规律)
- HDU 4662 MU Puzzle(找规律)
- Puzzle(HDU 6048)
- HDU 6048 Puzzle(找规律)——2017 Multi-University Training Contest
- HDU 1097 A hard puzzle(找规律,快速幂)
- HDU 1097 A hard puzzle (规律&&快速幂)
- POJ 2893 M × N Puzzle(逆序对-BIT)
- [逆序对] poj 2893 M × N Puzzle
- HDU 6048 Puzzle(机智)
- hdu 1271 整数对(找规律)
- HDU 1097 A hard puzzle 【快速幂 Or 规律(瞎搞)】
- HDU 1098 Ignatius's puzzle 【数学(特殊值总结) Or 规律(瞎搞)】
- HDU 4911 Inversion(逆序对-BIT)
- 网络判断+Fragment+ViewPager+XListView+TabLayout横向滑动菜单 Z2
- Linux下查看进程及删除进程
- smarty模板引擎中的判断句式、循环、文件引用和对象的引用
- 高斯混合模型(GMM)
- win10环境下搭建zookeeper伪集群
- hdu 6048 Puzzle(规律+逆序对)
- 解题笔记-n!(高精度阶乘(n<10000))
- 威盾V4补丁和升级包最新版本
- JSTL(第一节)
- iOS开发中info.plist相关配置(附iOS10权限设置)
- ES6的let和const
- 调整数组顺序使奇数位于偶数前面
- C#与Access数据库文件的创建
- 三维动态与交通运输的科学计算问题