Codeforces Round #364 (Div. 2), problem: (B) Cells Not Under Attack

来源:互联网 发布:挣钱的软件 编辑:程序博客网 时间:2024/05/01 14:49

题意:
给你一个地图。在其中安放炮塔。炮台可以打到与它同行同列的所有地方,求每一次安放一个炮台,剩余多少地方打不到

题解:
每一次认为是减少了矩形的长和宽,对于安放的地方已有同行的炮台,则只是矩形长减一,对于安放的地方已有同列的炮台,则只是矩形宽减一。

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>#include <stack>using namespace std;typedef pair<int, int> p;typedef long long ll;typedef unsigned long long ull;#define pr(x) cout << #x << ": " << x << "  "#define pl(x) cout << #x << ": " << x << endl;#define pri(a) printf("%d\n",(a))#define xx first#define yy second#define sa(n) scanf("%d", &(n))#define sal(n) scanf("%lld", &(n))#define sai(n) scanf("%I64d", &(n))#define vep(c) for(decltype((c).begin() ) it = (c).begin(); it != (c).end(); it++)int main(){    int n,num;    cin>>n>>num;    bool h[n+5];    bool l[n+5];    long long step = 1;    long long nx=n; long long ny=n;    long long ans[num+5];    memset(h,false,sizeof(h));    memset(l,false,sizeof(l));    int x;int y;    while(cin>>x>>y){        if(l[y]==false){          l[y]=true;            ny--;        }        if(h[x]==false){          h[x]=true;            nx--;        }        long long a = nx*ny;        ans[step] = a;        step++;    }    for(int i=1;i<=num;i++){        cout<<ans[i]<<" ";    }    return 0;}
0 0
原创粉丝点击