http://acm.hdu.edu.cn/showproblem.php?pid=4739

题意:

给定100*100的矩阵中n(n<= 20)个点,每次只能一走能够形成正方形的四个点,正方形平行于X,Y轴,求最多可以移除的点。

思路:

比赛时,脑子直接蒙了,或许是好久没做题的原因吧。哎...只要预处理出所有额正方形,然后注意处理重点情况就欧了。

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define ll long long
#define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define keyTree (chd[chd[root][1]][0])
#define Read() freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout); #define M 107
#define N 27 using namespace std; int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1}; const int inf = 0x7f7f7f7f;
const int mod = 1000000007;
const double eps = 1e-8;
const int R = 100007; struct sqp
{
int a1,a2,a3,a4;
}sq[M];
int nSq; struct Point
{
int x,y;
}p[N]; vector<int> pt[M][M];//记录每个位置点的个数
bool vt[M],use[M]; int n,ans; void dfs(int p,int num)
{
ans = max(ans,num);
for (int i = p; i < nSq; ++i)
{
int a1 = sq[i].a1,a2 = sq[i].a2,a3 = sq[i].a3, a4 = sq[i].a4;
if (!vt[a1] && !vt[a2] && !vt[a3] && !vt[a4])
{
vt[a1] = vt[a2] = vt[a3] = vt[a4] = true;
dfs(p + 1, num + 1);
vt[a1] = vt[a2] = vt[a3] = vt[a4] = false;
}
}
} int main()
{
while (scanf("%d",&n))
{
if (n == -1) break; for (int i = 0; i <= 100; ++i)
{
for (int j = 0; j <= 100; ++j)
{
pt[i][j].clear();
}
}
for (int i = 0; i < n; ++i)
{
scanf("%d%d",&p[i].x,&p[i].y);
pt[p[i].x][p[i].y].push_back(i);
}
nSq = 0; CL(use,false);
for (int i = 0; i < n; ++i)
{
int x = p[i].x;
int y = p[i].y;
int x1,y1;
if (pt[x][y].size() >= 4)//同一位置多个点的处理
{
for (size_t j = 0; j < pt[x][y].size(); j += 4)
{
sq[nSq].a1 = pt[x][y][j]; sq[nSq].a2 = pt[x][y][j + 1];
sq[nSq].a3 = pt[x][y][j + 2]; sq[nSq].a4 = pt[x][y][j + 3];
nSq++;
}
}
for (x1 = x + 1, y1 = y + 1; x1 <= 100 && y1 <= 100; ++x1, ++y1)
{
if (pt[x][y].size() > 0 && pt[x1][y].size() > 0 && pt[x][y1].size() > 0 && pt[x1][y1].size() > 0)
{
sq[nSq].a1 = pt[x][y][0];
sq[nSq].a2 = pt[x1][y][0];
sq[nSq].a3 = pt[x][y1][0];
sq[nSq].a4 = pt[x1][y1][0];
for (size_t j = 0; j < pt[x][y].size(); ++j)
{
if (!use[pt[x][y][j]])
{
sq[nSq].a1 = pt[x][y][j];
use[pt[x][y][j]] = true;
}
}
for (size_t j = 0; j < pt[x1][y].size(); ++j)
{
if (!use[pt[x1][y][j]])
{
sq[nSq].a2 = pt[x1][y][j];
use[pt[x1][y][j]] = true;
}
}
for (size_t j = 0; j < pt[x][y1].size(); ++j)
{
if (!use[pt[x][y1][j]])
{
sq[nSq].a3 = pt[x][y1][j];
use[pt[x][y1][j]] = true;
}
}
for (size_t j = 0; j < pt[x1][y1].size(); ++j)
{
if (!use[pt[x1][y1][j]])
{
sq[nSq].a4 = pt[x1][y1][j];
use[pt[x1][y1][j]] = true;
}
}
nSq++;
}
}
}
ans = 0; dfs(0,0); CL(vt,false);
printf("%d\n",ans*4);
}
return 0;
}

  

hdu 4739 Zhuge Liang's Mines DFS的更多相关文章

  1. hdu 4739 Zhuge Liang's Mines (简单dfs)

    Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. hdu 4739 Zhuge Liang's Mines 随机化

    Zhuge Liang's Mines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  3. HDU 4739 Zhuge Liang's Mines (2013杭州网络赛1002题)

    Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. hdu 4739 Zhuge Liang's Mines

    一个简单的搜索题,唉…… 当时脑子抽了,没做出来啊…… 代码如下: #include<iostream> #include<stdio.h> #include<algor ...

  5. HDU 4739 Zhuge Liang's Mines (状态压缩+背包DP)

    题意 给定平面直角坐标系内的N(N <= 20)个点,每四个点构成一个正方形可以消去,问最多可以消去几个点. 思路 比赛的时候暴力dfs+O(n^4)枚举写过了--无意间看到有题解用状压DP(这 ...

  6. HDOJ 4739 Zhuge Liang&#39;s Mines

    Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. 2013 ACM/ICPC Asia Regional Hangzhou Online hdu4739 Zhuge Liang's Mines

    Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  8. HDU 4772 Zhuge Liang&#39;s Password (简单模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 ...

  9. HDU 4048 Zhuge Liang's Stone Sentinel Maze

    Zhuge Liang's Stone Sentinel Maze Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/327 ...

随机推荐

  1. C# DateTime.Now详细用法

    //2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.ToString(& ...

  2. Thinkphp --- 去掉index.php

    这里我使用的面板是宝塔,操作的 apche: 具体的配置可以参考这里: https://www.cnblogs.com/fangziffff123/p/7588782.html 首先是:Thinkph ...

  3. Groovy中的面向对象

    Groovy中的面向对象 前面说到groovy支持脚本和类,前面一节已将简单说了脚本和类之间的关系,这一节主要介绍一下groovy中类的相关知识,即面向对象相关知识. 1.类型 1.1 原始类型 gr ...

  4. MegaCli 监控raid状态 限戴尔服务器

    MegaCli 监控raid状态 MegaCli是一款管理维护硬件RAID软件,可以通过它来了解当前raid卡的所有信息,包括 raid卡的型号,raid的阵列类型,raid 上各磁盘状态,等等.通常 ...

  5. android(十)smali

    Dalvik是google专门为Android操作系统设计的一个虚拟机,经过深度的优化.虽然Android上的程序是使用java来开发的,但是Dalvik和标准的java虚拟机JVM还是两回事. Da ...

  6. 【查看】mysql 常规书写注意事项(那些坑)

    mysql 常规书写注意事项,mysql注意事项 1. 注释:  -- 后面一定要加一个空格,否则会报错 2.注释:/*! content */ 在mysql中是会执行的,但是其他数据库不会.   例 ...

  7. innobackupex 还原和备份实例

    InnoDB 和非 InnoDB 文件的备份都是通过拷贝文件来做的,但是实现的方式不同,前者是以page为粒度做的(xtrabackup),后者是 cp 或者 tar 命令(innobackupex) ...

  8. java-mybaits-009-mybatis-spring-使用,SqlSessionFactoryBean、事务

    一.版本限制 参看地址:http://www.mybatis.org/spring/ 二.使用入门 2.1.pom <dependency> <groupId>org.myba ...

  9. jq的$(function(){})与window.onload的区别

    最近一直在研究jq的源码,书写jq的代码我们通常会包裹在一个$(function(){})函数中,jq的$(function(){})也就是$(document).ready(function(){} ...

  10. STL学习笔记--各种容器的运用时机

    如何选择最佳的容器类别? 缺省情况下应该使用vector.vector的内部结构简单,并允许随机存取,所以数据的存取十分方便灵活,数据的处理也够快. 如果经常要在序列的头部和尾部安插和移除元素,应采用 ...