题意:给定一个n*m个棋盘,放上一些棋子,问你最多能放几个炮(中国象棋中的炮)。

析:其实很简单,因为棋盘才是5*5最大,那么直接暴力就行,可以看成一行,很水,时间很短,才62ms。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e4 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n, m;
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[30];
int ans; bool isly(int x){
int b[] = { x+1, x-1, x+m, x-m};
int d[] = { x/m*m+m-1, x/m*m, n-1, 0};
int c[] = { 1, -1, m, -m}; for(int i = 0; i < 4; ++i){
bool ok = false;
for(int j = b[i]; (i & 1 ? j >= d[i] : j <= d[i]); j += c[i]){
if(ok && a[j] != -1){
if(a[j] == 1) return false;
else break;
}
else if(!ok && a[j] != -1) ok = true;
}
}
return true;
} void dfs(int x, int cnt){
ans = max(ans, cnt);
for(int i = x; i < n; ++i){
if(a[i] != -1 || !isly(i)) continue;
a[i] = 1;
dfs(i+1, cnt+1);
a[i] = -1;
}
} int main(){
int c;
while(scanf("%d %d %d", &n, &m, &c) == 3){
n *= m;
memset(a, -1, sizeof(a));
for(int i = 0; i < c; ++i){
int x, y;
scanf("%d %d", &x, &y);
a[x*m+y] = 0;
} ans = 0;
dfs(0, 0);
printf("%d\n", ans);
}
return 0;
}

最新文章

  1. cocoapods Analyzing dependencies 问题的解决方案
  2. DevExpress--navBarControl控件
  3. Call me evilxr
  4. spring注解 aop
  5. XMPP学习&mdash;&mdash;2、用户登录
  6. Sql Server之旅——第十二站 sqltext的参数化处理
  7. Beta版本冲刺———第六天
  8. php的字符串转2进制函数
  9. springMVC实现防止重复提交
  10. hdu 4635 Strongly connected(Tarjan)
  11. Translate one
  12. java高精度进制转换
  13. -_-#【Canvas】回弹
  14. 免费数据库(SQLite、Berkeley DB、PostgreSQL、MySQL、Firebird、mSQL、MSDE、DB2 Express-C、Oracle XE)
  15. Scanner扫描器
  16. React Native 轻松集成统计功能(Android 篇)
  17. mysql数据库truncate表时间长处理
  18. 并查集(POJ1182)
  19. struts2 contextMap
  20. idea遇到的坑

热门文章

  1. OpenERP 安装在Windows server上时间显示不对的解决办法
  2. mysql-备份和还原(普通还原和binlog还原)
  3. 韦东山驱动视频笔记——3.字符设备驱动程序之poll机制
  4. (转) Python Generators(生成器)——yield关键字
  5. QQ网站如何检测对本地已经登录的qq用户
  6. [转]就这样,创建了自己的运行时共享库(RSL)
  7. 平时学习HTML5及其安全相关的一些站点资源
  8. ORACLE 修改日志大小及增加日志成员
  9. mysql 表日常变化前几
  10. httpclient介绍