首页 > 其他分享 >HDU 4739 Zhuge Liang's Mines

HDU 4739 Zhuge Liang's Mines

时间:2022-11-09 19:03:20浏览次数:41  
标签:Yi HDU Liang int 4739 mines Shima Zhuge


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


暴力搜索好了

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=255;
int n,f[maxn],ans;

struct point
{
int x,y;
point(){}
point(int x,int y):x(x),y(y){}
void read(){scanf("%d%d",&x,&y);}
bool operator <(const point&a) const
{
if (x==a.x) return y<a.y;
return x<a.x;
}
}a[maxn];

void dfs(int x,int y)
{
if (x==n) return;
dfs(x+1,y);
if (f[x])
{
for (int i=x+1;a[i].x==a[x].x&&i<n;i++)
if (f[i])
{
for (int j=i+1;j<n;j++)
if (f[j]&&a[j].y==a[x].y&&a[j].x-a[x].x==a[i].y-a[x].y)
{
for (int k=j+1;a[j].x==a[k].x&&k<n;k++)
if (f[k]&&a[i].y==a[k].y)
{
f[x]=f[i]=f[j]=f[k]=0;
ans=max(ans,y+1);
dfs(x+1,y+1);
f[x]=f[i]=f[j]=f[k]=1;
}
}
}
}
}

int main()
{
while (~scanf("%d",&n),n>=0)
{
for (int i=0;i<n;i++) {a[i].read(); f[i]=1;}
sort(a,a+n);
dfs(ans=0,0);
printf("%d\n",ans*4);
}
return 0;
}



标签:Yi,HDU,Liang,int,4739,mines,Shima,Zhuge
From: https://blog.51cto.com/u_15870896/5838295

相关文章

  • HDU 3608 最长回文
    ProblemDescription给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度.回文就是正反读都是一样的字符串,如aba,abba等 Inp......
  • HDU 5591 ZYB's Game
    ProblemDescription withhisclassmatesinhiking:ahostkeepsanumberin  loses,orthehostwilltellalltheplayersthatthenumbernowisbigger......
  • HDU 4433 locker
    ProblemDescriptionApasswordlockerwithNdigits,eachdigitcanberotatedto0-9circularly.Youcanrotate1-3consecutivedigitsupordownino......
  • HDU 5586 Sum
    ProblemDescriptionThereisanumbersequence ,youcanselectainterval[l,r]ornot,allthenumbers  willbecome ..Afterthat,thesumofnnumbers......
  • HDU 4436 str2int
    ProblemDescriptionInthisproblem,youaregivenseveralstringsthatcontainonlydigitsfrom'0'to'9',inclusive.Anexampleisshownbelow.1......
  • HDU 5264 pog loves szh I
    ProblemDescriptionPoghaslotsofstrings.Andhealwaysmixestwoequal-lengthstrings.Forexample,therearetwostrings:"abcd"and"efgh".Afterm......
  • HDU 5639 Deletion
    ProblemDescriptionG with n verticesand m edges.Everytime,youcanselectseveraledgesanddeletethem.Theedgesselectedmustmeetthe......
  • HDU 5637 Transform
    ProblemDescriptionn integersaregiven.Foraninteger x youcandothefollowingoperations:+letthebinaryrepresentationof x be ......
  • HDU 1403 Longest Common Substring
    ProblemDescriptionGiventwostrings,youhavetotellthelengthoftheLongestCommonSubstringofthem.Forexample:str1=bananastr2=ciana......
  • HDU 4658 Integer Partition
    ProblemDescriptionGivenn,k,calculatethenumberofdifferent(unordered)partitionsofnsuchthatnopartisrepeatedkormoretimes.  ......