Hdu 6229 map fucks

This is Shenyang's M. To sort it out, it is probably to find the sum of the "Qi" in the lower right half compared to the total "Qi" in the top. Then use a map to simulate the process of adding obstacles. The map stores the points that have been deleted around and its remaining weights. To delete a point, first check whether there is this point in the map. If not, it is an isolated point, subtract the weight of this point, and Put the surrounding points into the map. Just keep maintaining the sum and the sum in the lower right corner.
Code:

#include <bits/stdc++.h>
using namespace std;
int n, k;
int sum, br;
map<pair<int, int>, int>mp;
set<pair<int, int> >deld;
int cal(int x, int y){
    int ans=5;
    if(x==0)ans--;
    if(x==n-1)ans--;
    if(y==0)ans--;
    if(y==n-1)ans--;
    return ans;
}
bool isbr(int x, int y){
    return x+y>=n-1;
}
void modify(int x, int y){
    if(x<0||x>=n||y<0||y>=n)return;
    pair<int, int> p=make_pair(x, y);
    if(deld.count(p))return;
    int tmp=1;
    sum-=tmp;
    if(isbr(x, y))br-=tmp;
    if(mp.find(p)!=mp.end())mp[p]--;
    else mp[p]=cal(x, y)-1;
    return;
}
void del(int x, int y){
    pair<int, int> p=make_pair(x, y);
    if(mp.find(p)!=mp.end()){
        int tmp=mp[p];
        sum-=tmp;
        if(isbr(x, y))br-=tmp;
        deld.insert(p);
    }
    else {
        int tmp=cal(x, y);
        sum-=tmp;
        if(isbr(x, y))br-=tmp;
        deld.insert(p);
    }
    modify(x-1, y);
    modify(x, y-1);
    modify(x+1, y);
    modify(x, y+1);

}
int main(){
    int T;
    scanf("%d", &T);
    for(int tt=1;tt<=T;tt++){
        scanf("%d%d", &n, &k);
        mp.clear();
        deld.clear();
        sum=5*n*n-4*n, br=(5*n*n+n-4)/2;
        for(int i=1;i<=k;i++){
            int x, y;
            scanf("%d%d", &x, &y);
            del(x, y);
        }
        int g=__gcd(sum, br);
        sum/=g, br/=g;
        printf("Case #%d: %d/%d\n", tt, br, sum);
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325945937&siteId=291194637