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. mongo 安装

    mongo 安装: 1.按照 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ 安装 2.安装成功后创建用户 d ...

  2. java 地址记录

    java在线API地址    http://docs.oracle.com/javase/7/docs/api/

  3. jQuery中的bind绑定事件与文本框改变事件的临时解决方法

    暂时没有想到什么好的解决办法,我现在加了个浏览器判断非ie的话就注册blur事件,这样有个问题就是blur实在别的控件活动焦点的时候,txtStation控件注册的方法是为了填充它紧挨着的一个下拉列表 ...

  4. Div 自适应屏幕大小

    http://blog.csdn.net/wodetiankong516/article/details/7827256 Background      有时, 我们需要将div或者其他的Elemen ...

  5. 使用VMware10虚拟机安装Linux系统(能力工场)

    作为IT从业人员,我们经常使用到Linux系统,但是实际开发过程我们通常在Windows平台操作,为了满足工作需要,这个时候我们通常在windows平台安装虚拟机,并在其上建立linux系统,这样就极 ...

  6. QCon 2013 上海 -- 高并发可用

      高并发可用应该是这次QCon的主要议题,目测超过一半的话题都在讨论这个主题或者和这个主题相关.看到Yun关于AWS re:Invent的总结,好像这个在AWS上也是很热的一个主题.就我个人而言,没 ...

  7. Masonry 实现输入框随键盘位置改变

    Github: https://github.com/saitjr/MasonryDemo 直接上代码: #import "ViewController4.h" #import & ...

  8. 【kd-tree】专题总结

    感谢orz神·小黑的指导 kd-tree就是用来计算若干维空间k近/远点的数(shou)据(suo)结(you)构(hua) 建树 假设题目是k维的点 第deep层就是用deep%k+1维把所有点分为 ...

  9. gradle 及 git 环境下利用hook及gradle脚本自动添加versioncode和versionname的方法

    在 app/build.gradle 文件里添加几行代码: def gitCommitShortHash = 'git log -1 --pretty=%h'.execute([], project. ...

  10. jbpm4.4+ssh配置(有些使用经验很好)

    http://www.cnblogs.com/cmzcheng/archive/2011/11/20/2255806.html ———————————————————————————————————— ...