HDU 6048 Puzzle(找规律)——2017 Multi-University Training Contest - Team 2
2017-07-31 19:03
691 查看
传送门
Total Submission(s): 405 Accepted Submission(s): 216
[align=left]Problem Description[/align] 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.
[align=left]Input[/align] 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).
[align=left]Output[/align] For each test case,print “YES” in a separate line if it is possible to complete the task ,otherwise please print “NO”.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
题目大意:
给定一个 n∗m 的方格和一个数字 p,将 [1,n∗m−1] 区间中排好序,依次选取 1, p+1, 2∗p+1, ... n∗p+1,将选取的数字从左至右,从上往下摆放,直到摆放到 [1,n∗m−1] 区间中的数都覆盖,现在的状态为初始的状态,现在问是否能从初始状态到达最终状态, 其中最终状态保证 每一行都是递增的,每一列都是递增的。如果能输出 YES,否则输出 NO。
解题思路:
其实题解已经说的很详细了,其实就是个找规律,然而发现找到这样的规律还是挺难的,只有多做题,多见识才能找到其中的规律。
官方题解:
Code:
Puzzle
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 405 Accepted Submission(s): 216
[align=left]Problem Description[/align] 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.
[align=left]Input[/align] 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).
[align=left]Output[/align] For each test case,print “YES” in a separate line if it is possible to complete the task ,otherwise please print “NO”.
[align=left]Sample Input[/align]
3 3 2 3 3 2 4 999 999 1
[align=left]Sample Output[/align]
YES NO YES
题目大意:
给定一个 n∗m 的方格和一个数字 p,将 [1,n∗m−1] 区间中排好序,依次选取 1, p+1, 2∗p+1, ... n∗p+1,将选取的数字从左至右,从上往下摆放,直到摆放到 [1,n∗m−1] 区间中的数都覆盖,现在的状态为初始的状态,现在问是否能从初始状态到达最终状态, 其中最终状态保证 每一行都是递增的,每一列都是递增的。如果能输出 YES,否则输出 NO。
解题思路:
其实题解已经说的很详细了,其实就是个找规律,然而发现找到这样的规律还是挺难的,只有多做题,多见识才能找到其中的规律。
官方题解:
Code:
#include <bits/stdc++.h> using namespace std; typedef long long LL; int main(){ int T; scanf("%d", &T); while(T--){ int n, m, p; scanf("%d%d%d", &n, &m, &p); LL all = n * m - 1, ans = 0; while(all > p){ LL tv = (all - 1) / p + 1; all -= tv; tv = (tv - 1) * tv / 2; ans += tv * (p - 1); } if(ans & 1) puts("NO"); else puts("YES"); } }
相关文章推荐
- HDU-6105 Gameia - 2017 Multi-University Training Contest - Team 6(思维之找规律或二分图最大匹配)
- HDU-6129 Just do it - 2017 Multi-University Training Contest - Team 7(规律、杨辉三角、组合数奇偶性)
- 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】
- HDU 6048 - Puzzle | 2017 Multi-University Training Contest 2
- hdu 6038 找规律 置换 2017 Multi-University Training Contest - Team 1
- HDU 6038 Function(找规律)——2017 Multi-University Training Contest - Team 1
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- 2017 Multi-University Training Contest - Team 1(hdu 6033 Add More Zero)
- HDU-6165 FFF at Valentine - 2017 Multi-University Training Contest - Team 9(强连通分量缩点+拓扑)
- hdu 6047 Maximum Sequence(2017 Multi-University Training Contest - Team 2)
- hdu 6045 Is Derek lying?(2017 Multi-University Training Contest - Team 2)
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- hdu 6051 If the starlight never fade [欧拉函数] [2017 Multi-University Training Contest - Team 2]
- 2017 Multi-University Training Contest - Team 2 :1006 Funny Function(找规律+逆元+快速幂取模)
- hdu 6058 Kanade's sum(链表)(2017 Multi-University Training Contest - Team 3 )
- hdu 6069 Counting Divisors(约数个数)(2017 Multi-University Training Contest - Team 4 )
- hdu 6070 Dirt Ratio(二分+线段树)(2017 Multi-University Training Contest - Team 4 )
- hdu 6071 Lazy Running(优先队列+dijkstra)(2017 Multi-University Training Contest - Team 4)
- hdu 6073 Matching In Multiplication(2017 Multi-University Training Contest - Team 4 )
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)