标签:arr Old Just int 第四场 cell grid 15 empty
Just an Old Puzzle
时间限制: 1 Sec 内存限制: 128 MB题目描述
You are given a 4 × 4 grid, which consists of 15 number cells and an empty cell.All numbers are unique and ranged from 1 to 15.
In this board, the cells which are adjacent with the empty cell can move to the empty cell.
Your task is to make the input grid to the target grid shown in the figure below.
In the following example (sample input), you can get the target grid in two moves.
输入
The first line contains an integer T (1 <= T <= 10^5) denoting the number of test cases.Each test case consists of four lines each containing four space-separated integers, denoting the input grid. 0 indicates the empty cell.
输出
For each test case, you have to print the answer in one line.If you can’t get the target grid within 120 moves, then print 'No', else print 'Yes'.
样例输入
2 1 2 3 4 5 6 7 8 9 10 0 12 13 14 11 15 1 2 3 4 5 6 7 8 9 10 11 12 13 15 14 0
样例输出
Yes No
代码
1 #include <bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 int arr[30]; 5 int main() 6 { 7 int t; 8 scanf("%d",&t); 9 while(t--) 10 { 11 for(int i=1;i<=4;i++) scanf("%d",&arr[i]); 12 for(int i=8;i>=5;i--)scanf("%d",&arr[i]); 13 for(int i=9;i<=12;i++)scanf("%d",&arr[i]); 14 for(int i=16;i>=13;i--)scanf("%d",&arr[i]); 15 int cnt=0; 16 for(int i=16;i>=1;i--) 17 for(int j=i-1;j>=1;j--) 18 if(arr[i]<arr[j]&&arr[i]!=0) 19 cnt++; 20 if(cnt&1)printf("Yes\n"); 21 else printf("No\n"); 22 } 23 return 0; 24 }View Code
标签:arr,Old,Just,int,第四场,cell,grid,15,empty 来源: https://www.cnblogs.com/CharlieWade/p/11285590.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。