Zhuge Liang's Mines

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

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
 

状压DP
四个点判断构成与坐标轴平行的正方形:
选任意3个点,枚举3个顶点判断是否可以构成等腰直角三角形,如果可以判断能否与第4个点构成正方形。。。。。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

struct node
{
    int x,y;
}p[30];

int dp[1050000],n;
vector<int> g[30];

bool Judge(int i,int j,int k,int l)
{
    node a=p,b=p[j],c=p[k],d=p[l];
    ///a-->d
    int x1=b.x-a.x,y1=b.y-a.y;
    int x2=c.x-a.x,y2=c.y-a.y;
    if(x1*x2-y1*y2==0)
    {
        int d1=x1*x1+y1*y1;
        int d2=x2*x2+y2*y2;
        if(d1==d2)
        {
            if((d.x==c.x&&d.y==b.y)||(d.x==b.x&&d.y==c.y))
                return true;
        }
    }
    ///b-->d;
    x1=a.x-b.x,y1=a.y-b.y;
    x2=c.x-b.x,y2=c.y-b.y;
    if(x1*x2-y1*y2==0)
    {
        int d1=x1*x1+y1*y1;
        int d2=x2*x2+y2*y2;
        if(d1==d2)
        {
            if((d.x==c.x&&d.y==a.y)||(d.x==a.x&&d.y==c.y))
                return true;
        }
    }
    ///c-->d
    x1=a.x-c.x,y1=a.y-c.y;
    x2=b.x-c.x,y2=b.y-c.y;
    if(x1*x2-y1*y2==0)
    {
        int d1=x1*x1+y1*y1;
        int d2=x2*x2+y2*y2;
        if(d1==d2)
        {
            if((d.x==b.x&&d.y==a.y)||(d.x==a.x&&d.y==b.y))
                return true;
        }
    }
    return false;
}
int main()
{
    while(scanf("%d",&n)&&~n)
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&p.x,&p.y);
        for(int i=0;i<30;i++)
            g.clear();
        memset(dp,0,sizeof(dp));
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                for(int k=j+1;k<n;k++)
                {
                    for(int l=k+1;l<n;l++)
                    {
                        if(Judge(i,j,k,l))
                        {
                            int status=0;
                            status=status|(1<<i)|(1<<j)|(1<<k)|(1<<l);
                            g.push_back(status);
                        }
                    }
                }
            }
        }
        for(int status=0;status<(1<<n);status++)
        {
             for(int i=0;i<n;i++)
             {
                 if(status&(1<<i))
                 {
                     for(int j=0;j<g.size();j++)
                     {
                         int s=g[j];
                         if((s|status)==status)
                         {
                             dp[status]=max(dp[status],dp[status^s]+4);
                         }
                     }
                 }
             }
        }
        printf("%d\n",dp[(1<<n)-1]);
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

HDOJ 4739 Zhuge Liang&#39;s Mines的更多相关文章

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

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

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

  4. HDU 4772 Zhuge Liang&#39;s Password (简单模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 ...

  5. hdu 4739 Zhuge Liang's Mines DFS

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

  6. hdu 4739 Zhuge Liang's Mines

    一个简单的搜索题,唉…… 当时脑子抽了,没做出来啊…… 代码如下: #include<iostream> #include<stdio.h> #include<algor ...

  7. HDU 4739 Zhuge Liang's Mines (状态压缩+背包DP)

    题意 给定平面直角坐标系内的N(N <= 20)个点,每四个点构成一个正方形可以消去,问最多可以消去几个点. 思路 比赛的时候暴力dfs+O(n^4)枚举写过了--无意间看到有题解用状压DP(这 ...

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

  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. STL之vector

    参考资料:      1.codeproject      2.csdn      3.cplusplus

  2. PHPExcel使用体会

    PHPExcel使用体会 因为毕设导师智能分配系统的需要,系负责人在管理学生和导师时,希望可以使用Excel批量导入学生和导师的信息,学长的报课系统使用的是PHPExcel的类库,于是我也抽空花了2天 ...

  3. hdu 3047–Zjnu Stadium(带权并查集)

    题目大意: 有n个人坐在zjnu体育馆里面,然后给出m个他们之间的距离, A B X, 代表B的座位比A多X. 然后求出这m个关系之间有多少个错误,所谓错误就是当前这个关系与之前的有冲突. 分析: 首 ...

  4. [USACO 2010 OPEN]SLIED

    传送门 这道题的题意描述简直有毒.题没看完一眼分层图,然后火速敲了个堆优化的dijkstra,然后就被样例教做人了QAQ 这里说的最坏的情况让我很迷茫?感觉很难判定到底什么是最坏的情况以及确定了最坏的 ...

  5. wpf 保存控件中的内容为图片格式

    黄色的是wpf控件的名称! //保存到特定路径            FileStream fs = new FileStream(@"C:\image.png", FileMod ...

  6. 用LinkedList模拟栈数据结构的集合

    用Eclipse软件进行操作    有2种方法,左边为第一种,右边为第二种 创建class为MyStack 代码实现: package cn_LinkedList;   import java.uti ...

  7. base64 convert to file

    var fs= require('fs') var imageFile = dataUrl.replace(/^data:image\/\w+;base64,/, ""); var ...

  8. 按照网上方法js删除指定cookie,却怎么也删除不了,解决如下

    网上方法: 查找原因说是没有指定Path,记得系统里以前也没指定还是可以的,就查了一下现在的系统Path,猜测是系统Path由以前的/改为/E7-Planning 就改了前端删除方法 测试一下OK了, ...

  9. Spring MVC学习笔记——POJO和DispatcherServlet

    POJO(Plain Ordinary Java Object)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创造的简称. 使用POJO名称是为了避免和EJB(Enter ...

  10. Eclipse中修改Web项目的URL访问路径

    背景 访问路径,也就是指在浏览器中访问该web系统时的根路径,比如http://localhost:8080/xxxx/index.jsp  这里的xxxx,也就是request.getContext ...