Zhuge Liang's Mines

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 239    Accepted Submission(s): 110

Problem 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
 
Source
 
Recommend
liuyiding
 

先预处理好哪些点的组合可以构成正方形。

然后按照二进制,去寻找答案。

虽然感觉复杂度比较大,但是还是过了。

 /* ***********************************************
Author :kuangbin
Created Time :2013/9/15 星期日 14:08:43
File Name :2013杭州网络赛\1002.cpp
************************************************ */ #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; pair<int,int>p[];
int n;
vector<int>vec; bool judge(pair<int,int>p1,pair<int,int>p2,pair<int,int>p3,pair<int,int>p4)
{
if(p3.first - p1.first != && p3.second - p1.second == p3.first - p1.first)
{
if(p2.first == p3.first && p2.second == p1.second)
if(p4.first == p1.first && p4.second == p3.second)
return true;
}
return false;
}
//判断p1p2p3p4四个点能不能形成正方形
bool check(pair<int,int>p1,pair<int,int>p2,pair<int,int>p3,pair<int,int>p4)
{
if(judge(p1,p2,p3,p4))return true;
if(judge(p1,p2,p4,p3))return true;
if(judge(p1,p3,p2,p4))return true;
if(judge(p1,p3,p4,p2))return true;
if(judge(p1,p4,p2,p3))return true;
if(judge(p1,p4,p3,p2))return true; swap(p1,p2);
if(judge(p1,p2,p3,p4))return true;
if(judge(p1,p2,p4,p3))return true;
if(judge(p1,p3,p2,p4))return true;
if(judge(p1,p3,p4,p2))return true;
if(judge(p1,p4,p2,p3))return true;
if(judge(p1,p4,p3,p2))return true;
swap(p1,p2); swap(p1,p3);
if(judge(p1,p2,p3,p4))return true;
if(judge(p1,p2,p4,p3))return true;
if(judge(p1,p3,p2,p4))return true;
if(judge(p1,p3,p4,p2))return true;
if(judge(p1,p4,p2,p3))return true;
if(judge(p1,p4,p3,p2))return true;
swap(p1,p3); swap(p1,p4);
if(judge(p1,p2,p3,p4))return true;
if(judge(p1,p2,p4,p3))return true;
if(judge(p1,p3,p2,p4))return true;
if(judge(p1,p3,p4,p2))return true;
if(judge(p1,p4,p2,p3))return true;
if(judge(p1,p4,p3,p2))return true;
swap(p1,p4); return false; } int dp[<<];
int solve(int s)
{
if(dp[s] != -)return dp[s];
int ans = ;
int sz = vec.size();
for(int i = ;i < sz;i++)
if((s&vec[i]) == vec[i])
{
ans = max(ans,+solve(s^vec[i]));
}
return dp[s] = ans;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d",&n) == )
{
if(n == -)break;
vec.clear();
for(int i = ;i < n;i++)
scanf("%d%d",&p[i].first,&p[i].second);
//找出所有可以组成正方形的组合
for(int i = ;i < n;i++)
for(int j = i+;j < n;j++)
for(int x = j+;x < n;x++)
for(int y = x+;y < n;y++)
if(check(p[i],p[j],p[x],p[y]))
{
vec.push_back((<<i)|(<<j)|(<<x)|(<<y));
}
memset(dp,-,sizeof(dp));
int tot = (<<n) -;
printf("%d\n",*solve(tot));
}
return ;
}

HDU 4739 Zhuge Liang's Mines (2013杭州网络赛1002题)的更多相关文章

  1. HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 4747 Mex (2013杭州网络赛1010题,线段树)

    Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  3. HDU 4741 Save Labman No.004 (2013杭州网络赛1004题,求三维空间异面直线的距离及最近点)

    Save Labman No.004 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. 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 ...

  5. 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 ...

  6. HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)

    Cut the Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)

    Count The Pairs Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  8. HDU 4758 Walk Through Squares (2013南京网络赛1011题,AC自动机+DP)

    Walk Through Squares Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Oth ...

  9. hdu 4739 Zhuge Liang's Mines DFS

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

随机推荐

  1. js深复制

    一般来讲深复制主要是为了复制js对象中的引用类型,引用类型在普通的赋值操作下相当于是引用,修改复制对象也会影响原对象,简单的方法的话可以使用JSON.parse(JSON.stringify(obj) ...

  2. matrix 矩阵(多维DP)

    题面 \(solution:\) 这一题其实就是一个非常明显的三维背包问题(但博主太弱了就10分QAQ) \(F[i][j][k]:\)表示走到\((i,j)\)这个位置并且背包容量为 \(k\) 时 ...

  3. 洛谷 P1478 陶陶摘苹果(升级版)

    本萌新第一次发布题解,若有不严谨处请谅解. 我看了前面几位大佬的手笔,表示自己还是比较钟爱桶排序的.它非常简易直接,还省时间,尤其对于这类题目占用的的空间也很小. 我们看到题目下面的说明:xi< ...

  4. artDialog学习之旅(一)

    接口 配置参数 content: {消息内容,支持HTML} title: {标题.默认:'提示'} lock: {是否锁定屏幕. 默认:false} width: {宽度,支持em等单位. 默认:' ...

  5. 以后的博客将更新到自己的域名pythonsite.com,欢迎访问

    以后的博客将更新到自己的域名pythonsite.com,欢迎访问

  6. python中的*号

    from:https://www.douban.com/note/231603832/ 传递实参和定义形参(所谓实参就是调用函数时传入的参数,形参则是定义函数是定义的参数)的时候,你还可以使用两个特殊 ...

  7. linux常用运维命令【转】

    自己的小网站跑在阿里云的ECS上面,偶尔也去分析分析自己网站服务器日志,看看网站的访问量.看看有没有黑阔搞破坏!于是收集,整理一些服务器日志分析命令,大家可以试试! 1.查看有多少个IP访问: awk ...

  8. 数据库SQL语句性能优化

    选择最有效率的表名顺序 ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最先处理,在FROM子句中包含多个表的情况下 ...

  9. make distclean

    清空bin目录make dirclean 清空所有相关的东西,包括下载的软件包,配置文件,feeds内容等make distclean 这个命令会删除feeds目录及其下面的所有的文件,直接结果就是运 ...

  10. IDEA配置文件的配置文件配置

    IDEA配置文件的配置文件配置: 路径 /Applications/IntelliJ IDEA 3.app/Contents/bin/idea.vmoptions (/IntelliJ IDEA 3. ...