CF #364 (Div. 2) (B. Cells Not Under Attack 标记)

本文介绍了一个关于棋盘覆盖的问题及其实现方法。在一个n*n的网格中放置棋子,每放置一个棋子,该行和列即被覆盖,文章提供了一段C++代码来计算放置m个棋子后剩余未被覆盖的点的数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目连接
在一个n*n的网格上,若果某个位置上放了一个棋子,那么棋子所在的行和列就算被覆盖了,每次放一个棋子问剩余的没有覆盖的点有几个

使用,两个数组分别标记行和列,在用两个变量保存X集合的可用数,Y集合的可用数,那么放入一个棋子,检查下X,Y集合就好了

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<bits/stdc++.h>
#include<map>
#include<string>
using namespace std;
#define cl(a,b) memset(a,b,sizeof(a))
#define LL long long
#define pb push_back
#define gcd __gcd

#define For(i,j,k) for(int i=(j);i<k;i++)
#define lowbit(i) (i&(-i))
#define _(x) printf("%d\n",x)

const int maxn = 1e5+200;
const LL inf  = 1LL << 34;

LL  n,m;
bool vis_x[maxn];
bool vis_y[maxn];

int cur_x,cur_y;

int main(){
    scanf("%lld%lld",&n,&m);
    LL sum = n*n;
    cur_x=cur_y=n;
    for(int i=0;i<m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        if(!vis_x[x]){sum-=cur_y;cur_x--;}
        if(!vis_y[y]){sum-=cur_x;cur_y--;}
        vis_x[x]=vis_y[y]=true;
        printf("%lld ",sum);
    }

    puts("");

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值