【UOJ 520】棋盘

【题目描述】:

给定一个n*n的棋盘,放置m颗棋子,一个位置是被攻击的当且仅当这个存在某个棋子和这个位置是同行或者同列,你需要在每次放置一颗棋子过后,给出不被攻击的位置数目。

【输入描述】:

第一行两个整数n,m。

接下来m行,每行两个整数x,y表示放置的行和列。

【输出描述】:

每行输出一个数表示当前不被攻击的位置数目。

【样例输入】:

3 3
1 1
3 1
2 2

【样例输出】:

4
2
0

【时间限制、数据范围及描述】:

时间:1s 空间:512M

对于30%的数据,n≤100,m≤10000;

对于50%的数据,n≤10^3,m<=10^5;

对于100%的数据,n,m≤10^5。

题解:这道题我在洛谷上做过相似的题目,马上上一篇就是了。

堪称小学数学题哈哈哈。

#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
typedef long long ll;
ll n,m,a,b,xx,yy;
ll x[100005],y[100005];
int main(){
    scanf("%lld %lld",&n,&m);
    while(m--){
        scanf("%lld %lld",&a,&b);
        if(x[a]==0) xx++;
        if(y[b]==0) yy++;
        x[a]=1; y[b]=1;
        printf("%lld
",((n-xx)*(n-yy)));
    }
    return 0;
}
原文地址:https://www.cnblogs.com/wuhu-JJJ/p/11216168.html