luogu P3913 car attack | Mathematics

Title Description

There the N × N chessboard KK a car, a car located on the first ii R_i row, first column C_i. Seeking the number grid by at least one car attack.

Car can attack all in the same place in the same row or column.

Input Format

Line 1, two integers N, K.

Next K lines of two integers R_i, C_i

Output Format

An integer representing the number of grid attack.


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e6+10;
#define int long long
struct node{
    int x,y;
}e[N];
int A[N],B[N];
signed main(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=k;i++){
        scanf("%lld%lld",&e[i].x,&e[i].y);
        A[i]=e[i].x;
        B[i]=e[i].y;
    }
    sort(A+1,A+1+k);
    sort(B+1,B+1+k);
    int x=unique(A+1,A+1+k)-A-1;
    int y=unique(B+1,B+1+k)-B-1;    
    cout<<x*n+y*n-x*y;
}

Guess you like

Origin www.cnblogs.com/naruto-mzx/p/11856062.html
car