hdu 4739 Zhuge Liang's Mines 随机化

Zhuge Liang‘s Mines

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4739

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

HINT

题意

每次可以去掉构成正方形的四个点,问你最多去掉多少个点

题解:

我不知道正解是爆搜还是状压……

反正我是随机化乱搞的……

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=2501;
#define mod 1000000009
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
//**************************************************************************************

struct node
{
    int x,y;
};
struct squal
{
    int kiss[4];
};
bool cmp(node a,node b)
{
    if(a.x==b.x)
        return a.y<b.y;
    return a.x<b.x;
}
node a[40];
int dp[40];
squal dis[300];
int n;
int dd;
void pre()
{
    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 t=k+1;t<n;t++)
                {
                    if(a[i].x==a[j].x&&a[i].y==a[k].y&&a[j].y==a[t].y&&a[k].x==a[t].x&&a[j].y-a[i].y==a[k].x-a[i].x)
                    {
                        dis[dd].kiss[0]=i;
                        dis[dd].kiss[1]=j;
                        dis[dd].kiss[2]=k;
                        dis[dd++].kiss[3]=t;
                    }
                }
            }
        }
    }
}
int main()
{

    while(cin>>n)
    {
        if(n==-1)
            break;
        memset(dis,0,sizeof(dis));
        memset(a,0,sizeof(a));
        memset(dp,0,sizeof(dp));
        for(int i=0;i<n;i++)
           a[i].x=read(),a[i].y=read();
        sort(a,a+n,cmp);
        dd=0;
        pre();
        if(dd==0)
        {
            puts("0");
            continue;
        }
        int flag[30];
        int ans=0;
        for(int i=0;i<1000;i++)
        {
            int ans1=0;
            memset(flag,0,sizeof(flag));
            for(int j=0;j<1000;j++)
            {
                int flag2=1;
                int aaa=rand()%dd;
                for(int k=0;k<4;k++)
                {
                    if(flag[dis[aaa].kiss[k]])
                        flag2=0;
                }
                if(flag2)
                {
                    ans1+=4;
                    for(int k=0;k<4;k++)
                    {
                        flag[dis[aaa].kiss[k]]++;
                    }
                }
            }
            ans=max(ans,ans1);
        }
        cout<<ans<<endl;
    }
}

hdu 4739 Zhuge Liang's Mines 随机化

时间: 2024-11-08 09:43:55

hdu 4739 Zhuge Liang's Mines 随机化的相关文章

HDU 4772 Zhuge Liang&#39;s Password

Problem Description In the ancient three kingdom period, Zhuge Liang was the most famous and smart military leader. His enemy was Sima Yi, the military leader of Kingdom Wei. Sima Yi always looked stupid when fighting against Zhuge Liang. But it was

HDU 4772 Zhuge Liang&#39;s Password 选择矩阵

本题需要使用选择矩阵的程序求解,这个和Leetcode上的一个程序是一样道理的.如果使用额外空间,那么是很容易做到的,这里不使用额外空间,直接使用到位操作,空间效率是O(1),这是个非常漂亮的到位旋转程序. 题意还是很重要,这次看错了一句话,就WA了一次: The maximum amount of cells which contains two equal numbers after overlapping, is the password. 这里是需要每次旋转之后求相同数字的最大值,而不是

HDU 4772 Zhuge Liang&#39;s Password (矩阵旋转)

Zhuge Liang's Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 931    Accepted Submission(s): 641 Problem Description In the ancient three kingdom period, Zhuge Liang was the most famous

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1404    Accepted Submission(s): 926 Problem Description In the anc

HDU 4772 Zhuge Liang&#39;s Password(模拟水)

HDU 4772 Zhuge Liang's Password 题目链接 题意:给定两张牌,可以旋转后重叠,重合后相同数字最多的是密码,求密码 思路:直接模拟记录最大值即可 代码: #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int N = 35; int n; int a[N][N], b[N][N]; int solve() { int

HDU 4048 Zhuge Liang&#39;s Stone Sentinel Maze

Zhuge Liang's Stone Sentinel Maze Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 385    Accepted Submission(s): 106 Problem Description Zhuge Liang was a chancellor of the state of Shu Han dur

hdu 4739Zhuge Liang&#39;s Mines(简单dfs,需要注意重点)

Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1166    Accepted Submission(s): 505 Problem Description In the ancient three kingdom period, Zhuge Liang was the most famous

HDU 6242 Geometry Problem(计算几何 + 随机化)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6242 思路:当 n == 1 时 任取一点 p 作为圆心即可. n >= 2 && n < 5 时 此时有可能出现所有点共线,所以取任意俩点间中点作为圆的圆心. n >= 5 保证了有解.所以不可能有所有点共线的情况,随机取三个点在正解圆上的概率是 1/8,还是蛮大的.... 外学了下随机算法的写法....时间种子 time(0)要强制转成int,不然会WA,不造为啥....

hdu4739(状压DP)

Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1318    Accepted Submission(s): 557 Problem Description In the ancient three kingdom period, Zhuge Liang was the most famous