bzoj3175tjoi2013 Attack device

Source: Internet
Author: User

3175: [Tjoi2013] Attack device Time Limit:10 Sec Memory limit:128 MB
submit:839 solved:418
[Submit] [Status] [Discuss] Description

Given a 01 matrix, where you can place the attack device in 0 locations. Each attack device (x, y) can be attacked by the word "day" in 8 locations (x-1,y-2), (x-2,y-1), (x+1,y-2), (x+2,y-1), (x-1,y+2), (x-2,y+1), (x+1,y+2), (x+2,y+1)
The maximum number of devices that can be placed in the case of non-attack by the device.
The first line of Input is an integer N, which indicates that the matrix size is n*n. Next n rows each row a length of N of 01 strings, representing the matrix. Output An integer that indicates the maximum number of devices that can be placed if the device is not attacking. Sample Input 3
010
000
100
Sample Output 4 HINT

100% Data n<=200



The maximum point independent set of two graphs



#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <cstdlib > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) #
Define ll Long long #define MAXN 40005 using namespace std;
int N,CNT,ANS,HEAD[MAXN],MATCH[MAXN];
int dx[8]={-1,-2,1,2,-1,-2,1,2},dy[8]={-2,-1,-2,-1,2,1,2,1};
BOOL F[205][205],VST[MAXN];
Char s[205]; struct Edge_type{int next,to;}
E[MAXN*8];
	inline int num (int x,int y) {return (x-1) *n+y;} inline void Add_edge (int x,int y) {e[++cnt]= (Edge_type) {head[x],y};
head[x]=cnt;
		} inline bool Dfs (int x) {for (int i=head[x];i;i=e[i].next) {int y=e[i].to;
			if (!vst[y]) {vst[y]=true; if (!match[y]| |
				DFS (Match[y])) {match[y]=x;
			return true;
}}} return false;
	} int main () {scanf ("%d", &n);
		F (i,1,n) {scanf ("%s", s+1);
	F (j,1,n) f[i][j]=s[j]== ' 0 '; } f (I,1,n) f (j,1,n) if (f[i][j]&& (i+j)%2) F (k,0,7) {int x=i+dx[k],y=j+DY[K]; if (x<1| | y<1| | x>n| |
		Y>n) continue;
		if (!f[x][y]) continue;
	Add_edge (Num (i,j), num (x, y));
	} f (I,1,n) f (j,1,n) if (f[i][j]) ans++;
		F (i,1,n) f (j,1,n) if (f[i][j]&& (i+j)%2) {memset (vst,false,sizeof (VST));
	if (DFS (num (i,j))) ans--;
	} printf ("%d\n", ans);
return 0;
 }


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.