BZOJ1054 [HAOI2008] Mobile Toys __bzoj

Source: Internet
Author: User

Just write an iteration a * and you can go through the search.

#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath > #include <ctime> #include <algorithm> #include <iomanip> #include <vector> #include <
stack> #include <queue> #include <map> #include <set> #include <bitset> using namespace std; #define MAXN 1010 #define MAXM 1010 #define LL Long #define INF 1000000000 #define MOD 1000000007 #define EPS 1e-8 St
	Ruct data{int F;
	int g;
	int D;
	Data () {} data (int _d,int _f);
	friend bool operator < (data x,data y) {return x.f+x.g>y.f+y.g;
}
};
Char s[5];
int s,t,d;
int mi[20];
int dis[1000010];
int Tim;
priority_queue<data>q;
	Data::d ata (int _d,int _f) {d=_d;
	F=_f;
	g=0;
	int t=d^t;
	int i;
		for (i=0;i<16;i++) {if (mi[i]&t) {g++;
	int read () {int i,j;
	int re=0;
	int now=1;
		for (i=1;i<=4;i++) {scanf ("%s", s+1);
			for (j=1;j<=4;j++) {re+= (s[j]== ' 1 ') *mi[(i-1) *4+j-1];
		now<<=1; }
	}
	return re;
	BOOL Search () {int i;
	Data x;
	Q.push (data (s,0));
	memset (dis,0x3f,sizeof (dis));
	dis[s]=0;
		while (!q.empty ()) {x=q.top ();
		Q.pop ();
		if (x.d==t) {return 1;
		} if (X.f==d) {continue; for (i=0;i<12;i++) {if (X.d&mi[i]) &&! (
				X.D&AMP;MI[I+4])) {int t=x.d^mi[i]^mi[i+4];
					if (dis[t]>x.f+1) {dis[t]=x.f+1;
				Q.push (data (t,x.f+1)); for (i=4;i<16;i++) {if (X.d&mi[i]) &&! (
				X.D&AMP;MI[I-4])) {int t=x.d^mi[i]^mi[i-4];
					if (dis[t]>x.f+1) {dis[t]=x.f+1;
				Q.push (data (t,x.f+1)); }} for (i=0;i<16;i++) {if (i==3| | i==7| | i==11| |
			I==15) {continue; The If ((X.d&mi[i)) &&! (
				X.D&AMP;MI[I+1])) {int t=x.d^mi[i]^mi[i+1];
					if (dis[t]>x.f+1) {dis[t]=x.f+1;
				Q.push (data (t,x.f+1)); }} for (i=0;i<16;i++) {if (i==0| | i==4| |
			I==8| |i==12) {continue; The If ((X.d&mi[i)) &&! ( X.d&mi[i-1])) {int t=x.d^mi[i]^mi[i-1];
					if (dis[t]>x.f+1) {dis[t]=x.f+1;
				Q.push (data (t,x.f+1));
return 0;
	int main () {int i;
	Mi[0]=1;
	for (i=1;i<16;i++) {mi[i]=mi[i-1]<<1;
	} s=read ();
	T=read (); for (d=0;;D
			+ +) {if (search ()) {printf ("%d\n", D);
		return 0;
} return 0;
 }/* 1111 0000 1110 0010 1010 0101 1010 0101 * *


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.