Seven Puzzle (AOJ 0121 bfs)
Seven PuzzleTime Limit: 1 sec, Memory Limit: 65536 KBSeven Puzzle
7. When there are 8 rows above the square, there will be two rows above the upper limit. When there are two rows above the upper limit, there will be two rows above the upper limit. Please wait until there are too many other users in each region. Please wait until then, 0, 1, 2 .... 7. There are two groups in the industry, two groups in the industry, and four groups in the industry.
7. When you begin, there will be no additional errors, and there will be no additional errors. When there are too many threads, there are too many threads, and the upper and lower left and right sides are connected to the upper and lower right sides. When the upper and lower right sides are connected, the upper and lower right sides are connected to each other. Zookeeper zookeeper, Zookeeper zookeeper () when there are too many requests, 0 when there are too many requests, right when there are too many requests, 7 when there are too many requests, then (B) the initial execution. When there are too many rows, then () if the initial shard contains 0 bytes, then the initial Shard is connected to the primary shard. If the initial shard contains 2 bytes, the primary Shard is transferred to the primary shard (c) the initial execution. When the zookeeper is in the same region as the zookeeper, the operation was completed successfully. Round () if the initial Shard is 0, then the upper and lower sides of the shard are connected to the upper and lower sides of the shard, then the upper limit is reached, and the upper limit is reached. for example, there may be too many requests.
There are two major causes for this problem. Initial initial then, attackers can perform the following operations. When the force was reached, there was a huge amount of money in the system. When there was a small amount of money in the system, there was a small amount of money in the system.
When the force is reached, the number of rows in the first row is 8, and the number of rows in the second row is too large. When there are two rows above, the initial two rows above each other and then there are two tables above each other. Numbers (a) Numbers.
|
|
Hybrid (c ), |
Limit (d), (the most dense sequence) |
Input
1) Numbers of numbers (integer; blank area cut) 2 numbers of numbers (integer; blank area cut )::
There are less than 1000 conflict between them.
Output
1. Maximum number of numbers) 2. the maximum number of hands in the migration region of a patient in a patient )::
Sample Input
0 1 2 3 4 5 6 71 0 2 3 4 5 6 77 6 5 4 3 2 1 0
Output for the Sample Input
0128
Question: 0 ~ The sequence of 7 (2*4) can only be 0 and the number around it. Ask how many times the sequence can be exchanged at least to 0 1 2 3 4 5 6 7 ideas: search and save all the answers. Because I did not write a wrong sentence at the time .. Code:
#include
#include
#include
#include #include
#include
#include
#include
#include
#include
#include
#pragma comment (linker,"/STACK:102400000,102400000")#define maxn 1005#define MAXN 2005#define mod 1000000009#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6#define lson rt<<1,l,mid#define rson rt<<1|1,mid+1,r#define FRE(i,a,b) for(i = a; i <= b; i++)#define FREE(i,a,b) for(i = a; i >= b; i--)#define FRL(i,a,b) for(i = a; i < b; i++)#define FRLL(i,a,b) for(i = a; i > b; i--)#define mem(t, v) memset ((t) , v, sizeof(t))#define sf(n) scanf("%d", &n)#define sff(a,b) scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pf printf#define DBG pf("Hi\n")typedef long long ll;using namespace std;struct St{ int x,y; int step; int g[2][4];};int dir[4][2]={0,1,0,-1,1,0,-1,0};int mp[2][4];map
ans;int a[8];int here(St s){ int i; int x=0; FRL(i,0,4) x=x*10+s.g[0][i]; FRL(i,0,4) x=x*10+s.g[1][i]; return x;}bool ok(St st){ if (st.x>=0&&st.x<2&&st.y>=0&&st.y<4) return true; return false;}void bfs(int sx,int sy){ int i; queue
Q; while (!Q.empty()) Q.pop(); St st,now; st.x=sx; st.y=sy; st.step=0; memcpy(st.g,mp,sizeof(mp)); ans[here(st)]=0; Q.push(st); while (!Q.empty()) { st=Q.front(); Q.pop(); FRL(i,0,4) { now.x=st.x+dir[i][0]; now.y=st.y+dir[i][1]; if (ok(now)) { memcpy(now.g,st.g,sizeof(st.g)); swap(now.g[st.x][st.y],now.g[now.x][now.y]); int xx=here(now); if (!ans[xx]) { now.step=st.step+1; ans[xx]=now.step; Q.push(now); } } } }}int main(){ int i,j; ans.clear(); FRL(i,0,4) mp[0][i]=i; FRL(i,0,4) mp[1][i]=i+4; int sx,sy; bfs(0,0); while (~scanf("%d",&a[0])) { FRE(i,1,7) sf(a[i]); St st; FRL(i,0,4) st.g[0][i]=a[i]; FRL(i,0,4) st.g[1][i]=a[i+4]; int xx=here(st); pf("%d\n",ans[xx]); } return 0;}