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 ...
 
随机推荐
- [非技术参考]C#基础:使用Thread创建线程(1)
			
Thread类可以创建和控制线程,Thread类的构造函数重载为接受ThreadStart和ParameterizedThreadStart类型的委托参数.下面我们用一个例子来解释怎样用Thread类 ...
 - SQL1-(增删改查、常用函数)
			
USE flowershopdb --全球唯一标识符(GUID UUID) SELECT NEWID() --增删改查 --INSERT [INTO] <表名> [列名] VALUES & ...
 - Android 汉字转拼音之工具篇
			
/* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Versi ...
 - firebug如何使用
			
1.怎么安装firebug: a.打开火狐浏览器--------b.点击火狐浏览器的右上角这个小图标-------c.点击<获取附件组件>,在右上角的搜索框()内,输入firebug,点击 ...
 - Category、Extension
			
Category,分类,类目.主要作⽤用是为没有源代码的添加方法,例系统自带的NSString. 通过Category添加的方法会成为原类的一部分.从⽽而达到扩展一 个类的功能. Category ...
 - 关于This的经典题目
			
这个题目见过很多次了 var x = 10; var foo = { x: 20, bar: function() { var x = 30; return this.x; } }; alert(fo ...
 - mysql 函数执行权限
			
mysql> show grants for query_all@'115.236.1x0.x'; +---------------------------------------------- ...
 - InitParam与ContextParm的异同
			
web.xml里面可以定义两种参数:(1)application范围内的参数,存放在servletcontext中,在web.xml中配置如下: xml 代码 <context-param> ...
 - Java图形化界面设计——布局管理器之null布局(空布局)
			
一般容器都有默认布局方式,但是有时候需要精确指定各个组建的大小和位置,就需要用到空布局. 操作方法: 1) 首先利用setLayout(null)语句将容器的布局设置为null布局(空布局 ...
 - CF#52 C  Circular RMQ  (线段树区间更新)
			
Description You are given circular array a0, a1, ..., an - 1. There are two types of operations with ...