HDU 4739 Zhuge Liang's Mines (2013杭州网络赛1002题)

时间:2022-09-18 10:47:20

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&&num;39&semi;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&period;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&&num;39&semi;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&&num;39&semi;s Mines &lpar;简单dfs&rpar;

    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自动机&plus;DP)

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

  9. hdu 4739 Zhuge Liang&&num;39&semi;s Mines DFS

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

随机推荐

  1. SQL Server 日期和时间函数

    http://www.cnblogs.com/adandelion/archive/2006/11/08/554312.html 1.常用日期方法(下面的GetDate() = '2006-11-08 ...

  2. MIT 6&period;828 JOS学习笔记6&period; Appendix 1&colon; 实模式&lpar;real mode&rpar;与保护模式&lpar;protected mode&rpar;

    在我们阅读boot loader代码时,遇到了两个非常重要的概念,实模式(real mode)和保护模式(protected mode). 首先我们要知道这两种模式都是CPU的工作模式,实模式是早期C ...

  3. Math&period;Round四舍五入

    Math.Round函数四舍五入的问题   今天客户跑过来跟我说,我们程序里面计算的价格不对,我检查了一下,发现价格是经过折算后的价格,结果是可能小数位较多,而单据上只能打印两位价格,所以就对价格调用 ...

  4. HDU 5828 Rikka with Sequence &lpar;线段树&plus;剪枝优化&rpar;

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5828 给你n个数,三种操作.操作1是将l到r之间的数都加上x:操作2是将l到r之间的数都开方:操作3是 ...

  5. &lbrack;转&rsqb;JQuery&period;Ajax之错误调试帮助信息

    下面是Jquery中AJAX参数详细列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求 ...

  6. Kerberos和NTLM - SQL Server

    当我们使用Windows Authentication去连接SQL Server的时候,SQL Server可能会使用Kerberos或者是NTLM来进行认证,有时间就会因为认证失败的缘故造成各种登录 ...

  7. Tomcat安装和目录简介

    要知道动态的网页必须要有服务器的支撑! 1.知名的java web服务器 Tomcat:Apache组织发布,免费开源的,轻量级 JBoss.WebLogic是商用的,价格较高,但相对于开源的更加稳定 ...

  8. Cisco IP 电话 将它的voice mail 发送到手机

    功能一.将语音转成文字发送短信(有微软认知.百度认知.云片短信API) 功能二.直接将音频发送到微信 不废话,直接送个包 链接: https://github.com/JaviZhu/KLCN.Spe ...

  9. Angular2入门:TypeScript的类型 - 类型、null、undefined

  10. Windows环境下实现Consul服务注册和服务发现

    1.首先从官方网站下载Consul,因为我们是使用的Windows系统,所以选择windows版本 https://www.consul.io/downloads.html 2.可以用开发者模式来启动 ...