Bzoj 3232: Enclosure game 01 Score Planning

Source: Internet
Author: User

First two-point answer (Dinkelbach. Don't know if it's OK), and then it becomes possible to judge.

Here is a more ingenious way, is to set a direction for the enclosure, it may be counter-clockwise, then go upward is equivalent to the left side of the answer to add it, go down is equivalent to the left side of the answer to subtract, and then determine whether there is a negative power loop.

In addition, the network flow map, all blocks from the s edge capacity for value, and then add a circle to the t edge capacity of Benquan inf, and then any two adjacent blocks (including the outside lap) with the two-way edge capacity for the cost of the edge. Then run the minimum cut to subtract from the answer.

The AC code is as follows:

#include <iostream> #include <cstdio> #include <cstring> #define N #define M 100005 using namespace std

;
int m,n,cnt,h[m+5][2],s[n][n],mp[n][n][4],num[n][n]; Double d[n][n],len[n][n][4];
BOOL Bo[n][n];
	const int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};//0 on 1 2 left 3 right bool OK (double t) {int i,j,k,x,y;
				For (i=0, i<=m; i++) for (j=0; j<=n; j + +) for (k=0; k<4; k++) {x=i+dx[k]; y=j+dy[k];
					if (x>=0 && x<=m && y>=0 && y<=n) {len[i][j][k]=mp[i][j][k]*t; if (!k) len[i][j][k]-=s[i][j];
				else if (k==1) len[i][j][k]+=s[i+1][j];
	}} int head=0,tail=cnt,u=0,v=0;
		for (I=1; i<=cnt; i++) {h[i][0]=u; h[i][1]=v; if (v<n) v++;
	else{u++; v=0;} } memset (Bo,0,sizeof (bo));
	memset (num,0,sizeof (num));
		while (Head!=tail) {head=head%m+1; x=h[head][0]; y=h[head][1]; bo[x][y]=1;
			for (i=0; i<4; i++) {u=x+dx[i]; v=y+dy[i]; if (u>=0 && u<=m && v>=0 && v<=n) IF (D[x][y]+len[x][y][i]<d[u][v]) {d[u][v]=d[x][y]+len[x][y][i];
					num[u][v]=num[x][y]+1;
					if (num[u][v]>cnt) return 1;
						if (Bo[u][v]) {bo[u][v]=0; tail=tail%m+1; H[tail][0]=u;
					H[tail][1]=v;
}}}} return 0;
	} int main () {scanf ("%d%d", &m,&n); cnt= (m+1) * (n+1); int i,j,x;
		for (I=1; i<=m; i++) for (j=1; j<=n; J + +) {scanf ("%d", &x); s[i][j]=s[i][j-1]+x;
			} for (i=0; i<=m; i++) for (j=1; j<=n; J + +) {scanf ("%d", &x);
		Mp[i][j][2]=mp[i][j-1][3]=x;
			} for (I=1; i<=m; i++) for (j=0; j<=n; J + +) {scanf ("%d", &x);
		Mp[i][j][0]=mp[i-1][j][1]=x;
	} double L=0,r=m*n*100,mid;
		while (L+1e-6<r) {mid= (l+r)/2; if (OK (mid)) L=mid;
	else R=mid;
	} printf ("%.3f\n", (L+R)/2);
return 0;
 }


by Lych

2016.4.13

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.