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 ...
随机推荐
- WPF:向客户端发出某一属性值已更改的通知INotifyPropertyChanged接口
Person.cs using System.ComponentModel; namespace _01_INotifyPropertyChanged { class Person:INotifyPr ...
- VirtualBox 更改主机和虚拟机之间的鼠标切换热键
VirtualBox 主机和虚拟机之间的鼠标切换热键 是 Right Ctrl.一般用惯VM Ware的都不太习惯,那么怎么改变VirtualBox鼠标切换热键呢? 1.点击菜单栏的 管理--&g ...
- python初探-数据类型
数据类型 可以使用BIF type()来查看对象的类型 数字 int float long 布尔(bool) True 机内表示1,机器识别非0 False 机内表示0,机器识别0 空值 None 字 ...
- Dockerfile
http://blog.csdn.net/jiashiwen/article/details/48806243 一:如何使用: Dockerfile 用来创建一个自定义的image,包含了用户指定的软 ...
- JS行合并处理方法
//行合并 function _w_table_rowspan(col){ _w_table_firsttd = ""; _w_table_currenttd = "&q ...
- MySQL学习系列一---命令行连接mysql和执行sql文件
1.命令行连接mysql #mysql -h(主机) -u(用户名) -p (数据库名) mysql -hlocalhost -uroot -p testdb Enter password: **** ...
- fiddler--手机https
1.访问fiddler的主讲加端口,比如我的是:http://192.168.1.103:8080 在点击fiddlerroot certificate 下载安装证书即可
- CCNA实验(8) -- PPP & HDLC
HDLC帧格式与以太帧格式有很大差别,HDLC帧没有源MAC和目的MAC地址.HDLC不能提供验证,缺少对链路保护.Cisco设备与Cisco设备连接,可用HDLC封装.Cisco设备与非Cisco设 ...
- 怎样从一个DLL中导出一个C++类
原文作者:Alex Blekhman 翻译:朱金灿 原文来源: http://www.codeproject.com/KB/cpp/howto_export_cpp_classes.aspx 译 ...
- java ssh
sshj (currently best choice) https://github.com/shikhar/sshj ssh used in jenkins-ci https://github.c ...