跳到正文

题解

【题解】P6200

do_while_false约 2 分钟
原文
文章信息与版本

文章信息

发布
2020年3月11日
收录
2026年9月29日
更新
2026年11月21日
篇幅
约 2 分钟
获赞
6
题目
P6200

版本

  1. v1当前

这题暴力枚举即可。

直接记录,左右是 xx,上下是 yy,左上到右下是 x−y+nx-y+n,右上到左下是 x+y−1x+y-1,注意可能站在对手的位置射击。

C++
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int maxn=510,inf=1e9;
int n,k,x,y,z,tot,ans;
int row[maxn],col[maxn],lt[maxn],rt[maxn],map1[maxn][maxn];
inline int read() {//快读 
	int r=0;bool flag=true;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') flag=false;ch=getchar();}
	while(ch>='0'&&ch<='9'){r=(r<<3)+(r<<1)+(ch^48);ch=getchar();}
	return flag==true?r:~r+1;
}
int main(void) {
    n=read();
    k=read();
    for(int i=1;i<=k;i++) {
        x=read();
        y=read();
		map1[x][y]++;
        row[x]++;col[y]++;lt[x-y+n]++;rt[x+y-1]++;
    }
    for(int i=1;i<=n;i++)
    	for(int j=1;j<=n;j++)
    		if(row[i]+col[j]+lt[i-j+n]+rt[i+j-1]-3*map1[i][j]==k) 
				ans++;
    printf("%d\n",ans);
    return 0;
}
原文
抓取于
  1. dyq_QWQ

    qpzc

  2. do_while_false

    时间复杂度 $O(nk)$