Gym - 101196H Vin Diagrams

Topic link: https://vjudge.net/problem/Gym-101196H
Title: Give you two circles A and B of convex polygons, let you count out that A contains several points that do not intersect with B, B contains several points that do not intersect with A, and how many points do A and B intersect with each other?
Analysis: This kind of problem is xjb dyeing. Anyway, it's dying. My method is to add a circle outside the whole graph and dye the edge of A. The dyeing method is to dye all the outside of circle A into one color if you can keep walking. After dyeing, all the outside of circle A is dyed into another color, and then the inside is dyed into another color. B is the same. The last number of colors is good.

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
using namespace std;
const int maxn = 105;
int vis[maxn][maxn];
int vis1[maxn][maxn];
int vis2[maxn][maxn];
char a[maxn][maxn];
int n,m;
int dx[] = {0,0,1,-1,};
int dy[] = {1,-1,0,0,};
void colorA(int i,int j,int clo);
void dfsA(int i,int j,int dir,int clo);
void colorB(int i,int j,int clo);
void dfsB(int i,int j,int dir,int clo);
void dfs(int i,int j,int clo,int vis[105][105])
{
    for(int k=0;k<4;k++)
    {
        int tx = i+dx[k];
        int ty = j+dy[k];
        if(vis[tx][ty])
            continue;
        if(tx<0 || ty<0 || tx>n+1 || ty>m+1)
            continue;
        vis[tx][ty] = clo;
        dfs(tx,ty,clo,vis);
    }
}
bool checkA(int i,int j)
{
    if(i<0||j<0||i>n||j>m)
        return false;
    if(vis1[i][j]==1)
        return false;
    return a[i][j]=='X'||a[i][j]=='A';
}
bool checkB(int i,int j)
{
    if(i<0||j<0 || i>n+1 || j>m+1)
        return false;
    if(vis2[i][j]==2)
        return false;
    return a[i][j]=='X'||a[i][j]=='B';
}
void colorA(int i,int j,int clo)
{
    if(checkA(i,j+1))
        dfsA(i,j+1,0,clo);
    else if(checkA(i,j-1))
        dfsA(i,j-1,1,clo);
    else if(checkA(i+1,j))
        dfsA(i+1,j,2,clo);
    else if(checkA(i-1,j))
        dfsA(i-1,j,3,clo);
}
void colorB(int i,int j,int clo)
{
    if(checkB(i,j+1))
        dfsB(i,j+1,0,clo);
    else if(checkB(i,j-1))
        dfsB(i,j-1,1,clo);
    else if(checkB(i+1,j))
        dfsB(i+1,j,2,clo);
    else if(checkB(i-1,j))
        dfsB(i-1,j,3,clo);
}
void dfsA(int i,int j,int dir,int clo)
{
    vis1[i][j] = clo;
    if(checkA(i+dx[dir],j+dy[dir]))
        dfsA(i+dx[dir],j+dy[dir],dir,clo);
    else
        colorA(i,j,clo);
}
void dfsB(int i,int j,int dir,int clo)
{
    vis2[i][j] = clo;
    if(checkB(i+dx[dir],j+dy[dir]))
        dfsB(i+dx[dir],j+dy[dir],dir,clo);
    else
        colorB(i,j,clo);
}
int main()
{
    memset(vis,0,sizeof(vis));
    memset(vis1,0,sizeof(vis1));
    memset(vis2,0,sizeof(vis2));
    scanf("%d %d",&n,&m);
    for(int i=0;i<=n;i++)
        a[n+1][i] = a[i][m+1] = a[0][i] = a[i][0] = '.';
    for(int i=1;i<=n;i++)
        scanf("%s",a[i]+1);
    int ax,ay,bx,by;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(a[i][j]=='A')
                ax=i,ay=j;
            if(a[i][j]=='B')
                bx=i,by=j;
        }
    }
    colorA(ax,ay,1);
    colorB(bx,by,2);
    vis1[0][0] = 6;
    vis2[0][0] = 6;
    dfs(0,0,6,vis1);
    dfs(0,0,6,vis2);
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(vis1[i][j]==0 && a[i][j]=='.')
                vis1[i][j] = 3;
            if(vis2[i][j]==0 && a[i][j]=='.')
                vis2[i][j] = 4;
        }
    }
//    for(int i=0;i<=n;i++)
//    {
//        for(int j=0;j<=m;j++)
//            printf("%d ",vis1[i][j]);
//        puts("");
//    }
//    puts("");
//    for(int i=0;i<=n;i++)
//    {
//        for(int j=0;j<=m;j++)
//            printf("%d ",vis2[i][j]);
//        puts("");
//    }
    int ans1 = 0,ans2 = 0,ans3 = 0;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(vis1[i][j]==3&&a[i][j]=='.')
                ans1++;
            if(vis2[i][j]==4&&a[i][j]=='.')
                ans2++;
            if(vis1[i][j]==3&&vis2[i][j]==4&&a[i][j]=='.')
                ans3++;
        }
    }
    printf("%d %d %d\n",ans1-ans3,ans2-ans3,ans3);
    return 0;
}

Posted by pedroteixeira07 on Mon, 11 Feb 2019 03:03:18 -0800