Zhuge Liang's Mines

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

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
 

先暴力找出所有的正方形(因为地雷最多只有20个,所以n^4完全没问题),再0,1背包下选那些正方形能选到最多正方形就行了。

 #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <queue>
#include <map> using namespace std;
typedef struct abcd
{
double x,y;
} abcd;
abcd a[];
int t;
int maxa;
int c[];
int b[][];
bool cmp(abcd x,abcd y)
{
if(x.x!=y.x)return x.x<y.x;
else return x.y<y.y;
}
void dfs(int x,int sum)
{
if(x>=t)
{
if(maxa<sum)
maxa=sum;
return ;
}
int i;
int fla=;
for(i=x;i<t;i++)
{
if((c[b[i][]]||c[b[i][]]||c[b[i][]]||c[b[i][]])==)
{
fla=;
c[b[i][]]=;c[b[i][]]=;c[b[i][]]=;c[b[i][]]=;
dfs(i+,sum+);
c[b[i][]]=;c[b[i][]]=;c[b[i][]]=;c[b[i][]]=;
}
}
if(!fla)
{
if(maxa<sum)
maxa=sum;
}
}
int fun(int i,int j,int x,int y)
{
if(a[i].x==a[j].x&&a[j].x==a[x].x) return ;
if(a[i].y==a[j].y&&a[j].y==a[x].y) return ;
if(a[i].x!=a[j].x||a[x].x!=a[y].x)
return ;
if(a[i].y!=a[x].y||a[j].y!=a[y].y)
return ;
if(a[j].y-a[i].y!=a[x].x-a[i].x)
return ;
else return ;
}
int main()
{
int n; while(scanf("%d",&n))
{
if(n==-)
break;
int i,j,x,y;
for(i=; i<n; i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
}
sort(a,a+n,cmp);
memset(c,,sizeof(c));
maxa=;
t=;
for(i=; i<n; i++)
{
for(j=i+; j<n; j++)
{
for(x=j+; x<n; x++)
{
for(y=x+; y<n; y++)
{
if(fun(i,j,x,y))
{
b[t][]=i;
b[t][]=j;
b[t][]=x;
b[t][]=y;
t++;
}
}
}
}
}
dfs(,);
cout<<maxa<<endl;
}
}

2013 ACM/ICPC Asia Regional Hangzhou Online hdu4739 Zhuge Liang's Mines的更多相关文章

  1. hdu 4747 Mex (2013 ACM/ICPC Asia Regional Hangzhou Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4747 思路: 比赛打得太菜了,不想写....线段树莽一下 实现代码: #include<iost ...

  2. [2013 ACM/ICPC Asia Regional Hangzhou Online J/1010]hdu 4747 Mex (线段树)

    题意: + ;];;;], seg[rt <<  | ]);)) * fa.setv;) * fa.setv;;], seg[rt <<  | ], r - l + );;,  ...

  3. HDU4745——Two Rabbits——2013 ACM/ICPC Asia Regional Hangzhou Online

    这个题目虽然在比赛的时候苦思无果,但是赛后再做就真的是个水题,赤果果的水题. 题目的意思是给n个数构成的环,两只兔子从任一点开始分别顺逆时针跳,每次可以调到任意一个数(最多不会跳过一圈). 求最多能跳 ...

  4. HDU4747——2013 ACM/ICPC Asia Regional Hangzhou Online

    啦啦啦. 这是杭州网赛的一个题目,当时没做出来,当然这个想法确实比较难想到. 题目质量很高,这个题目也很特别,以前都没做过类似的题目.让我又一次体验了线段树的强大力量. 题目的意思是给你n个数a1-a ...

  5. HDU 4745 Two Rabbits(最长回文子序列)(2013 ACM/ICPC Asia Regional Hangzhou Online)

    Description Long long ago, there lived two rabbits Tom and Jerry in the forest. On a sunny afternoon ...

  6. HDU 4744 Starloop System(最小费用最大流)(2013 ACM/ICPC Asia Regional Hangzhou Online)

    Description At the end of the 200013 th year of the Galaxy era, the war between Carbon-based lives a ...

  7. HDU 4747 Mex(线段树)(2013 ACM/ICPC Asia Regional Hangzhou Online)

    Problem Description Mex is a function on a set of integers, which is universally used for impartial ...

  8. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  9. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

随机推荐

  1. [2013-06-05]bat脚本设置DNS

    有时候需要切换本机dns,将网络环境转至测试环境 @echo off netsh interface ip set dns name="本地连接" source=static ad ...

  2. 消息摘要技术(MD5)

    1.使用消息摘要技术对密码加密 数据库存储的是经过消息摘要技术加密之后的信息, 避免保存密码明文,提升了系统安全性 必要性说明: 如果存储明文密码,数据库系统管理员和攻破系统的黑客是可以拿到你的所有信 ...

  3. VS2012启用angularjs智能提示Intelligence

    过程为一下步骤: 1.关闭掉你打开的VS 2.进入VS的安装目录,默认安装一般为下边这个 C:\Program Files (x86)\Microsoft Visual Studio 11.0\Com ...

  4. VS2012启用angularjs智能提示Intelligence(转)

    1. 關閉正在執行的 Visual Studio 2012 2. 開啟檔案總管,並進入以下目錄: C:\Program Files (x86)\Microsoft Visual Studio 11.0 ...

  5. Ubuntu操作系统下安装JDK、tomcat、mysql

    1.先从安装虚拟机开始 01.首先打开VMware虚拟机.     02.然后,进入home主页,点击"create a New Virtual Machine"一栏,就会弹出一个 ...

  6. NHibernate教程(12)--延迟加载

    本节内容 引入 延迟加载 实例分析 1.一对多关系实例 2.多对多关系实例 结语 引入 通过前面文章的分析,我们知道了如何使用NHibernate,比如CRUD操作.事务.一对多.多对多映射等问题,这 ...

  7. 自制EIGRP配置实验大全

    EIGRP综合实验 本实验可能会有一两个出错的地方,希望大家进行实验测试后,可以指正!当然绝大部分都是正确滴! 实验A:基本配置 A.0)实验目的: 熟悉eigrp的基本配置 A.1)实验拓扑: A. ...

  8. 201521123023《Java程序设计》第五周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 2. 书面作业 Q1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过 ...

  9. 201521123077 《Java程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 异常分为uncheckedException和checkedException checkedException 继 ...

  10. 201521123064 《Java程序设计》第10周学习总结

    1. 本章学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. ① 定义Thread类的子类,覆盖Thread类的run()方法,然后创建该子类的实例(一般不用该方法,开销 ...