Zhuge Liang's Mines

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

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

Description

In the ancient three kingdom period, Zhuge Liang was the most famous and smartest military leader. His enemy was Shima Yi, who always looked stupid when fighting against Zhuge Liang. But it was Shima Yi who laughed to the end.

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.

Input

There are no more than 15 test cases.
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.

Output

For each test case ,print the maximum number of mines Shima Yi removed in a line.

Sample Input

3
1 1
0 0
2 2
8
0 0
1 0
2 0
0 1
1 1
2 1
10 1
10 0
-1

Sample Output

0
4

HINT

题意

每次可以去掉构成正方形的四个点,问你最多去掉多少个点

题解:

我不知道正解是爆搜还是状压……

反正我是随机化乱搞的……

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=;
#define mod 1000000009
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** struct node
{
int x,y;
};
struct squal
{
int kiss[];
};
bool cmp(node a,node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
node a[];
int dp[];
squal dis[];
int n;
int dd;
void pre()
{
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
for(int k=j+;k<n;k++)
{
for(int t=k+;t<n;t++)
{
if(a[i].x==a[j].x&&a[i].y==a[k].y&&a[j].y==a[t].y&&a[k].x==a[t].x&&a[j].y-a[i].y==a[k].x-a[i].x)
{
dis[dd].kiss[]=i;
dis[dd].kiss[]=j;
dis[dd].kiss[]=k;
dis[dd++].kiss[]=t;
}
}
}
}
}
}
int main()
{ while(cin>>n)
{
if(n==-)
break;
memset(dis,,sizeof(dis));
memset(a,,sizeof(a));
memset(dp,,sizeof(dp));
for(int i=;i<n;i++)
a[i].x=read(),a[i].y=read();
sort(a,a+n,cmp);
dd=;
pre();
if(dd==)
{
puts("");
continue;
}
int flag[];
int ans=;
for(int i=;i<;i++)
{
int ans1=;
memset(flag,,sizeof(flag));
for(int j=;j<;j++)
{
int flag2=;
int aaa=rand()%dd;
for(int k=;k<;k++)
{
if(flag[dis[aaa].kiss[k]])
flag2=;
}
if(flag2)
{
ans1+=;
for(int k=;k<;k++)
{
flag[dis[aaa].kiss[k]]++;
}
}
}
ans=max(ans,ans1);
}
cout<<ans<<endl;
}
}

hdu 4739 Zhuge Liang's Mines 随机化的更多相关文章

  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 (2013杭州网络赛1002题)

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

  3. hdu 4739 Zhuge Liang's Mines DFS

    http://acm.hdu.edu.cn/showproblem.php?pid=4739 题意: 给定100*100的矩阵中n(n<= 20)个点,每次只能一走能够形成正方形的四个点,正方形 ...

  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++ STL编程轻松入门基础

    C++ STL编程轻松入门基础 1 初识STL:解答一些疑问 1.1 一个最关心的问题:什么是STL 1.2 追根溯源:STL的历史 1.3 千丝万缕的联系 1.4 STL的不同实现版本 2 牛刀小试 ...

  2. VC++中内存对齐

    我们经常看到求 sizeof(A) 的值的问题,其中A是一个结构体,类,或者联合体. 为了优化CPU访问和优化内存,减少内存碎片,编译器对内存对齐制定了一些规则.但是,不同的编译器可能有不同的实现,本 ...

  3. Initializing a Build Environment

    This section describes how to set up your local work environment to build the Android source files. ...

  4. OpenGl从零开始之坐标变换(上)

    坐标变换是深入理解三维世界的基础,非常重要.学习这部分首先要清楚几个概念:视点变换.模型变换.投影变换.视口变换. 在现实世界中,所有的物体都具有三维特征,但计算机本身只能处理数字,显示二维的图形,因 ...

  5. 【JNI】OPUS压缩与解压的JNI调用(.DLL版本)

    OPUS压缩与解压的JNI调用(.DLL版本) 一.写在开头: 理论上讲,这是我在博客园的第一篇原创的博客,之前也一直想找个地方写点东西,把最近做的一些东西归纳总结下,但是一般工程做完了一高兴就把东西 ...

  6. Spring Batch的事务-Part 1:基础

    原文 https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-1-the-basics/ This is th ...

  7. PHP强大的内置filter (一)

    <?php #PHP内置的validate filter $input_data = True; $result = filter_var($input_data,FILTER_VALIDATE ...

  8. debian7下部署nginx服务器

    笔者是在vmware中的Debian7下部署nginx服务器,采用离线部署方式.过程如下: 1.准备好需要的离线安装包 nginx-1.6.2.tar.gz,pcre-8.34.tar.gz,open ...

  9. JIT(动态编译)和AOT(静态编译)编译技术比较

    Java 应用程序的性能经常成为开发社区中的讨论热点.因为该语言的设计初衷是使用解释的方式支持应用程序的可移植性目标,早期 Java 运行时所提供的性能级别远低于 C 和 C++ 之类的编译语言.尽管 ...

  10. 一排下去再上来的div

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...