hdu 4739 Zhuge Liang's Mines (简单dfs)
Zhuge Liang's Mines
Once, Zhuge Liang sent the arrogant Ma Shu to defend Jie Ting, a very important fortress. Because Ma Shu is the son of Zhuge Liang's good friend Ma liang, even Liu Bei, the Ex. king, had warned Zhuge Liang that Ma Shu was always bragging and couldn't be used, Zhuge Liang wouldn't listen. Shima Yi defeated Ma Shu and took Jie Ting. Zhuge Liang had to kill Ma Shu and retreated. To avoid Shima Yi's chasing, Zhuge Liang put some mines on the only road. Zhuge Liang deployed the mines in a Bagua pattern which made the mines very hard to remove. If you try to remove a single mine, no matter what you do ,it will explode. Ma Shu's son betrayed Zhuge Liang , he found Shima Yi, and told Shima Yi the only way to remove the mines: If you remove four mines which form the four vertexes of a square at the same time, the removal will be success. In fact, Shima Yi was not stupid. He removed as many mines as possible. Can you figure out how many mines he removed at that time?
The mine field can be considered as a the Cartesian coordinate system. Every mine had its coordinates. To simplify the problem, please only consider the squares which are parallel to the coordinate axes.
In each test case:
The first line is an integer N, meaning that there are N mines( 0 < N <= 20 ).
Next N lines describes the coordinates of N mines. Each line contains two integers X and Y, meaning that there is a mine at position (X,Y). ( 0 <= X,Y <= 100)
The input ends with N = -1.
1 1
0 0
2 2
8
0 0
1 0
2 0
0 1
1 1
2 1
10 1
10 0
-1
4
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define maxn 105
using namespace std; int n,m,ans;
bool mp[maxn][maxn];
int vis[maxn][maxn];
struct Node
{
int x,y;
} pp[21]; bool cmp(Node xx,Node yy)
{
if(xx.y!=yy.y) return xx.y<yy.y;
if(xx.x!=yy.x) return xx.x<yy.x;
}
void dfs(int pos,int val)
{
if(ans<val) ans=val;
if(pos>n||val+n-pos+1<=ans) return ;
int i,j,x,y,tx,ty,edge;
x=pp[pos].x;
y=pp[pos].y;
if(vis[x][y]<=0) dfs(pos+1,val);
else
{
for(i=pos+1; i<=n; i++)
{
tx=pp[i].x;
ty=pp[i].y;
if(ty>y) break ;
edge=tx-x;
if(edge==0) continue ;
if(mp[x][y+edge]&&mp[tx][y+edge])
{
if(vis[x][y]<=0||vis[tx][ty]<=0||vis[x][y+edge]<=0||vis[tx][y+edge]<=0) continue ;
vis[x][y]--,vis[tx][ty]--;
vis[x][y+edge]--,vis[tx][y+edge]--;
dfs(pos+1,val+4);
vis[x][y]++,vis[tx][ty]++;
vis[x][y+edge]++,vis[tx][y+edge]++;
}
}
dfs(pos+1,val);
}
}
int main()
{
int i,j;
while(scanf("%d",&n))
{
if(n==-1) break ;
memset(mp,0,sizeof(mp));
memset(vis,0,sizeof(vis));
for(i=1; i<=n; i++)
{
scanf("%d%d",&pp[i].x,&pp[i].y);
mp[pp[i].x][pp[i].y]=1;
vis[pp[i].x][pp[i].y]++;
}
sort(pp+1,pp+n+1,cmp);
ans=0;
dfs(1,0);
printf("%d\n",ans);
}
return 0;
}
hdu 4739 Zhuge Liang's Mines (简单dfs)的更多相关文章
- 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 ...
- 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 ...
- hdu 4739 Zhuge Liang's Mines DFS
http://acm.hdu.edu.cn/showproblem.php?pid=4739 题意: 给定100*100的矩阵中n(n<= 20)个点,每次只能一走能够形成正方形的四个点,正方形 ...
- hdu 4739 Zhuge Liang's Mines
一个简单的搜索题,唉…… 当时脑子抽了,没做出来啊…… 代码如下: #include<iostream> #include<stdio.h> #include<algor ...
- HDU 4739 Zhuge Liang's Mines (状态压缩+背包DP)
题意 给定平面直角坐标系内的N(N <= 20)个点,每四个点构成一个正方形可以消去,问最多可以消去几个点. 思路 比赛的时候暴力dfs+O(n^4)枚举写过了--无意间看到有题解用状压DP(这 ...
- HDOJ 4739 Zhuge Liang's Mines
Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 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 ...
- HDU 4772 Zhuge Liang's Password (简单模拟题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 ...
- 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 ...
随机推荐
- Scala学习之for 循环和 yield 的例子
for循环中的 yield 会把当前的元素记下来,保存在集合中,循环结束后将返回该集合.Scala中for循环是有返回值的.如果被循环的是Map,返回的就是Map,被循环的是List,返回的就是Lis ...
- Hibernate学习之常用方法比较
一.save()和persist()方法 使用 save() 方法保存持久化对象时,该方法返回该持久化对象的标识属性值(即对应记录的主键值):但使用 persist() 方法来保存持久化对象时,该方法 ...
- 数据库分页【Limt与Limt..OFFSET 】
数据起始 SELECT * from xiaoyao_blogs_essay limit 20 , 15;解释:20是起始位置,15是页容量.因为id是从15开始的 SELECT * from xi ...
- mongodb数据库调试问题:‘db object already connecting, open cannot be called multiple times’
在微博小系统的调试过程中: (1)登入登出可以正常显示,就是在注册的时候网络连接突然停止,但是用户名和密码已经存入数据库中,报错为:undefined is not a function 错误主要指向 ...
- Anndroid 开发架构读书笔记
市面上大部分应用不外乎就是颠过来倒过去地做以下这些事情: --------------- --------------- --------------- --------------- | | | | ...
- 树莓派高级GPIO库,wiringpi2 for python使用笔记(一)安装
网上的教程,一般Python用RPi.GPIO来控制树莓派的GPIO,而C/C++一般用wringpi库来操作GPIO,RPi.GPIO过于简单,很多高级功能不支持,比如i2c/SPI库等,也缺乏高精 ...
- Ping pong(树状数组经典)
Ping pong Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- CentOS 6.4 U盘启动盘制作、安装及遇到的问题解决
用UltraISO Premium Edition 9.3 制作的CentOS 6.4 U盘安装盘, 制作过程參考我写的百度经验:UltraISO制作U盘系统盘安装CentOS经验分享 安装时提示P ...
- .NET + Jcrop 实现在线裁图功能
最近有这样一个需求,因为一个门户网站首页展示图片很长但很矮,自己截图怕有不到位,所以利用JQUERY 的 Jcrop组件做了一个在线裁图的功能. 初始化 $('#oldpicImg').Jcrop({ ...
- Ajax异步请求XMLHttpRequest对象Get请求
$(function () { $("#btnGetDate").click(function () { var xhr; //第一步:创建异步请求的核心的对象: if (XMLH ...