[bzoj-3175] [Tjoi2013] Attack device

Source: Internet
Author: User

Topic Portal
Test Instructions Analysis: The topic is to give you a picture of n*n, some points in the figure can be put chess pieces, some can not, here the pieces with the horse like Walking "Day", and then asked you can put a few non-attacking horses.

My Opinion: see this can not attack each other problem, violence points may be used DFS, but here n<=200, so of course, the DFS dichotomy is matched, the building is very obvious, as long as a point can be attacked to all points connected to a side, and then run a binary map matching on the line. The last match is the number of points that cannot be placed on a piece. But here's a problem, because you can't (maybe Dalao did it, but I'm konjac konjac not) to divide the points into two sides, so the last match will be twice times the right one.
Summary:
1, enter the post-build diagram.
2, run the two-point map matching.
3, the total output of 0 points minus ans/2 (ans is the answer to the two-point chart).

the code to run the thief slowly:

#include <iostream> #include <cmath> #include <cstdio> #include <cstring> #include <  Algorithm> #define REP (I,a,n) for (int. i=a;i<=n;i++) #define PER (i,a,n) for (int i=a;i>=n;i--) #define CLEAR (a,x)
memset (A,x,sizeof (a)) #define LL Long long #define INF 2000000000 #define EPS 1e-8 using namespace std;
    ll read () {ll x=0,f=1;
    Char Ch=getchar (); while (ch< ' 0 ' | |
    Ch> ' 9 ') f=ch== '-'? -1:f,ch=getchar ();
    while (ch>= ' 0 ' &&ch<= ' 9 ') x=x*10+ch-' 0 ', Ch=getchar ();
return x*f;
} const int maxn=205,maxm=40005;;
const int dx[8]={-1,-2,-2,-1,1,2,2,1}, dy[8]={-2,-1,1,2,2,1,-1,-2};
Char MAP[MAXN][MAXN];
int MATCH[MAXM];
int head[maxm],vet[maxm<<4],next[maxm<<4];
BOOL FLAG[MAXM];
int len,n,sum;
    int calc (int x,int y) {return (x-1) *n+y;} void Add (int u,int v) {vet[++len]=v;
    Next[len]=head[u];
Head[u]=len;
        } bool Dfs (int u) {for (int e=head[u];e;e=next[e]) {int v=vet[e]; if (Flag[v]) conTinue;
        int T=MATCH[V];
        Match[v]=u;
        Flag[v]=1; if (t==-1| |
        DFS (t)) return true;
    match[v]=t;
} return false;
    } int main () {n=read ();
    Rep (i,1,n) scanf ("%s", map[i]+1); Rep (I,1,n) Rep (j,1,n) if (map[i][j]== ' 0 ') rep (k,0,7) {int x=i+dx[k
                    ],Y=J+DY[K]; if (x<1| | x>n| | y<1| | y>n| |
                    map[x][y]== ' 1 ') continue;
                Add (Calc (i,j), calc (x, y));
    } Clear (match,-1);
    int ans=0;
            Rep (I,1,n) Rep (j,1,n) if (map[i][j]== ' 0 ') {sum++;
            Clear (flag,0); 
            Flag[calc (i,j)]=1;
        Ans+=dfs (Calc (i,j));
    } printf ("%d\n", SUM-ANS/2);
return 0; }

Attach AC record:

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.