题意:$n*m$棋盘放置k个皇后,问几个格子不被攻击 1≤n,m≤20000,1≤k≤500

开set判重暴力$O(n*k)$然而,setMLE了QAQ

正解确实是$O(n*k)$的

以hang[i]记录此行是否被占用

用c[i]动态维护没被占用的行有几个安全的,(枚举皇后打标记)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<set>
using namespace std;
#define olinr return
#define _ 0
#define love_nmr 0
#define DB double
int x[];
int y[];
bool hang[];
bool c[];
inline int read()
{
int x=,f=;
char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
f=-f;
ch=getchar();
}
while(isdigit(ch))
{
x=(x<<)+(x<<)+(ch^);
ch=getchar();
}
return x*f;
}
inline void put(int x)
{
if(x<)
{
x=-x;
putchar('-');
}
if(x>)
put(x/);
putchar(x%+'');
}
int n;
int m;
int k;
int ans;
int main()
{
n=read();
m=read();
k=read();
for(int i=;i<=k;i++)
{
x[i]=read();
y[i]=read();
hang[x[i]]=true;
}
for(int i=;i<=n;i++)
{
if(!hang[i])
{
memset(c,,sizeof c);
int sum=m;
for(int j=;j<=k;j++)
{
if(!c[y[j]]) //枚举所占列,sum--
{
c[y[j]]=true;
sum--;
}
if(y[j]+x[j]-i>=&&y[j]+x[j]-i<=m&&!c[y[j]+x[j]-i]) //自己推一下,神奇的事情发生了! 这居然是皇后左下到右上对角线与当前行交点的y!!!!!!!
{
c[y[j]+x[j]-i]=true;
sum--;
}
if(y[j]-x[j]+i>=&&y[j]-x[j]+i<=m&&!c[y[j]-x[j]+i]) //这里是从右下到左上的交点
{
c[y[j]-x[j]+i]=true;
sum--;
}
}
ans+=sum; //统计安全~~~~~的
}
}
put(ans);
olinr ~~(^_^)+love_nmr;
}

最新文章

  1. 各种HTTP状态的含义
  2. Fragment全解析系列(一):那些年踩过的坑
  3. WCF 异步调用问题
  4. 《DDNS服务器的搭建和案例解决方法》
  5. Case when 的用法,简单Case函数
  6. dfs+dp思想的结合------hdu1078
  7. salesforce 零基础学习(六十六)VF页面应善于使用变量和函数(二)常用函数的使用
  8. javascript定义二维数组与添加
  9. zabbix部署
  10. js检测数据类型四种办法
  11. Linq(高级查询)
  12. cad2016卸载/安装失败/如何彻底卸载清除干净cad2016注册表和文件的方法
  13. oracle查询2G以上的表
  14. Spring-IOC MethodInvokingFactoryBean 类源码解析
  15. poj 3415 后缀数组 两个字符串中长度不小于 k 的公共子串的个数
  16. 什么是集群(Cluster)技术
  17. Python并行编程(十二):进程同步
  18. APP纯黑盒测试—某些可以试试的操作
  19. 文本处理三剑客之 Sed &mdash;&mdash;高级编辑命令
  20. HDU 4609 FFT模板

热门文章

  1. android-auto-scroll-view-pager (无限广告轮播图)
  2. Ros学习——roslaunch
  3. Ros学习service——小海龟
  4. cocos2d-js动作模块使用(自用,只有代码)
  5. JS对表单的操作
  6. tar打包tar.gz文件
  7. 杭电acm 1021题
  8. 855C Helga Hufflepuff&#39;s Cup
  9. PCL基础3.2-如何编写新的PCL类
  10. 使用IDEA开发SPARK提交remote cluster执行