棋盘

题解:

如果这道题直接用模拟做的话一定会超时的,而且空间上也容易触界。也就是说,这道题只能用数字进行加减而不能用数组来模拟。那么一开始不被攻击的位置又n*n个,当放下第一个棋子时,先操作x轴,将n*n减去一个n,并且把这一行标记为已经操作过,然后总的y轴上的棋子增加一个。当下一次放y轴时,因为刚才放x轴时占了一个位置,我们要少减一个,然后总的x轴上的棋子增加一个。这样的做法巧妙地避开了二维数组和重叠的问题。

代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<cctype>
#include<climits>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#define MAXA 100005
#define ipt(x) scanf("%d",&x)
using namespace std;
typedef long long LL;
int n,m,x,y,xPut,yPut;
LL cnt;
bool is_xPut[MAXA],is_yPut[MAXA];
int main() {
	//freopen("chess.in","r",stdin);
	//freopen("chess.out","w",stdout);
	ipt(n);
	ipt(m);
	cnt = (LL)n * n;
	for(int i=0;i<=m-1;i++) {
		ipt(x);
		ipt(y);
		if(!is_xPut[x]) {
			is_xPut[x] = true;
			cnt -= (n - xPut);
			yPut++;
		}
		if(!is_yPut[y]) {
			is_yPut[y] = true;
			cnt -= (n - yPut);
			xPut++;
		}
		printf("%lld\n",cnt);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值