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/Others)
Total Submission(s): 239 Accepted Submission(s): 110
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.
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.
1 1
0 0
2 2
8
0 0
1 0
2 0
0 1
1 1
2 1
10 1
10 0
-1
4
先预处理好哪些点的组合可以构成正方形。
然后按照二进制,去寻找答案。
虽然感觉复杂度比较大,但是还是过了。
/* ***********************************************
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题)的更多相关文章
- HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4747 Mex (2013杭州网络赛1010题,线段树)
Mex Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- HDU 4750 Count The Pairs (2013南京网络赛1003题,并查集)
Count The Pairs Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others ...
- 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 ...
- hdu 4739 Zhuge Liang's Mines DFS
http://acm.hdu.edu.cn/showproblem.php?pid=4739 题意: 给定100*100的矩阵中n(n<= 20)个点,每次只能一走能够形成正方形的四个点,正方形 ...
随机推荐
- CS229 笔记07
CS229 笔记07 Optimal Margin Classifier 回顾SVM \[ \begin{eqnarray*} h_{w,b}&=&g(w^{\rm T}x+b)\\[ ...
- [BZOJ 1013][JSOI 2008] 球形空间产生器sphere 题解(高斯消元)
[BZOJ 1013][JSOI 2008] 球形空间产生器sphere Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面 ...
- 机器学习&深度学习视频资料汇总
第一部分 基础语言 pandax视频教程 链接: https://pan.baidu.com/s/1pLqavVX 密码: fath python入门到精通 链接: https://pan.b ...
- python爬虫-图片批量下载
# 爬起摄图网的图片批量下载# coding:utf-8 import requests from bs4 import BeautifulSoup from scipy.misc import im ...
- 【比赛游记】NOIP2017游记
身为FJ的选手,在师大附中AHSOFNU考试,环境很不错,考得也还可以吧...[考的并不好] 不过比赛前都在划水233333 另:看到这篇博客的OIer们一定要评论啊! Day1的中午,因为穿了短袖去 ...
- Shell-遍历删除指定目录
Code: find $LibPath/ -name .svn | xargs rm -rf
- arm交叉编译器gnueabi、none-eabi、arm-eabi、gnueabihf等的区别【转】
转自:https://www.cnblogs.com/deng-tao/p/6432578.html 博客来之于: http://www.veryarm.com/296.html 交叉编译工具链的命 ...
- 大数据系列之分布式计算批处理引擎MapReduce实践-排序
清明刚过,该来学习点新的知识点了. 上次说到关于MapReduce对于文本中词频的统计使用WordCount.如果还有同学不熟悉的可以参考博文大数据系列之分布式计算批处理引擎MapReduce实践. ...
- springboot---->集成mybatis开发(一)
这里面我们介绍一下springboot与mybatis的集成,主要完成了mybatis的真分页.一个成熟的人往往发觉可以责怪的人越来越少,人人都有他的难处. springboot简单集成mytbati ...
- android 通用 Intent
通用 Intent 本文内容显示详细信息 闹钟 日历 相机 联系人/人员应用 电子邮件 文件存储 本地操作 地图 音乐或视频 新笔记 电话 搜索 设置 发送短信 网络浏览器 使用 Android 调试 ...