usaco Picture

 

 

/*
ID: modengd1
PROG: picture
LANG: C++
*/
#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <vector>
#include <algorithm>
using namespace std;
int N;
struct edge
{
    int y,x1,x2;
    bool isbegin;
    bool friend operator<(edge e1,edge e2)
    {
        if(e1.y!=e2.y)
            return e1.y<e2.y;
        return e1.isbegin;
    }
};
int slove(edge ES[20000])
{
    int cnt[40010];
    sort(ES,ES+(N<<1));
    memset(cnt,0,sizeof(cnt));
    int ans=0;
    for(int i=0;i<(N<<1);i++)
    {
        for(int j=ES[i].x1;j<ES[i].x2;j++)
        {
            if((cnt[j]==0&&ES[i].isbegin)||(cnt[j]==1&&!ES[i].isbegin))
                ans++;
            if(ES[i].isbegin)
                cnt[j]++;
            else
                cnt[j]--;
        }
    }
    return ans;
}
int main()
{
    freopen("picture.in","r",stdin);
    freopen("picture.out","w",stdout);

    edge ER[20000],EC[20000];
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        int x1,x2,y1,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        x1+=10000;
        x2+=10000;
        y1+=10000;
        y2+=10000;
        ER[i<<1]=edge{y1,x1,x2,true};
        ER[i<<1|1]=edge{y2,x1,x2,false};

        EC[i<<1]=edge{x1,y1,y2,true};
        EC[i<<1|1]=edge{x2,y1,y2,false};
    }
    cout<<slove(ER)+slove(EC)<<endl;
    return 0;
}

  

posted on 2015-10-21 22:18  insaneman  阅读(137)  评论(0编辑  收藏  举报

导航