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. win 7 下Maven环境的搭建

    Apache Maven,是一个软件(特别是Java软件)项目管理及自动构建工具. Maven是什么? 比较正式的定义:Maven是一个项目管理工具,它包含了: 一个项目对象模型 (Project O ...

  2. OFBIZ+ECLIPSE

    1. 首先要安装好OFBIZ,参考<OFBIZ安装>. 2. 安装ECLIPSE. 3. 安装FreeMarker插件,这是OFBIZ的模版引擎.在"Eclipse Market ...

  3. cookie跨域,跨目录访问及单点登录。

    首先普及下域名的知识: 域名: baidu.com    // 一级域名  A play.baidu.com  //  二级域名 B abc.play.baidu.com // 三级域名  C 数有几 ...

  4. 2014搜狗前端面经【B事业部】

    本来就投了一份简历,后来又收到了个B事业部的面试电话,今天刚面完一面,总体感觉还是很基础的,其中一名面试官帅到不行啊!另一个也不差,真是幸胡...(sorry,跑题了...) 上来先做了份笔试题,超级 ...

  5. c/c++ 数字转成字符串, 字符串转成数字

    c/c++ 数字转成字符串, 字符串转成数字 ------转帖 数字转字符串: 用C++的streanstream: #include <sstream> #Include <str ...

  6. 动态创建二维vector数组 C和C++ 及指针与引用的区别

    二维vectorvector<vector <int> > ivec(m ,vector<int>(n));    //m*n的二维vector 动态创建m*n的二 ...

  7. Axure rp 基础知识 转

    首先做个声明:此次教程里为了快速完成,借用了一些网上已有教程的图文,不是剽窃,只图方便.另外,因为汉化版本可能功能名称等略有差别,请自行理解. 名词解释: 线框图:一般就是指产品原型,比如:把线框图尽 ...

  8. BIOS启动项中的设备都有哪些

    Floppy 软式磁盘驱动器,简称FDD,也就是我们平时所说的软驱. CD-ROM 不用多说了,大家都知道,这是光盘驱动器,也就是我们平时说得光驱. SCSI SCSI的全名是:Small Compu ...

  9. 快速入门linux系统的iptables防火墙 1 本机与外界的基本通信管理

    概述 iptables是一种运行在linux下的防火墙组件,下面的介绍可以快速的学习iptables的入门使用. 特点(重要) 它的工作逻辑分为 链.表.规则三层结构. 数据包通过的时候,在对应表中, ...

  10. ECMAScript 6 入门学习笔记(持续更新)

    1.let命令(作用同var) ES6新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. { let a = 10; var b = 1; } ...