A、1001
hdu4738 Caocao's Bridges
注意需要有人送炸弹去 = =。。。所以不可能为0.。。呵呵
B、1002
hdu 4739 Zhuge Liang's Mines
直接递归枚举即可 = =,自己写得确实复杂了= =
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
using namespace std;
#define llg long long
template<typename T> inline void checkMin(T& a, T b) { if (a > b) a = b; }
template<typename T> inline void checkMax(T& a, T b) { if (a < b) a = b; }
template<class T> inline T Min(T x,T y){return (x>y?y:x);}
template<class T> inline T Max(T x,T y){return (x<y?y:x);}
struct po{
int x,y;
}point[30];
int cmp(po a,po b)
{
if(a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
int vis[30];
int n;
int ans = 0;
bool hash[110][110];
void dfs(int now,int cnt)
{
if(now == n){
ans = cnt > ans ? cnt : ans;
return ;
}
if(vis[now] == true){
dfs(now + 1,cnt);
return ;
}
int next = now;
while(1)
{
next++;
if(point[now].x != point[next].x || next > n) break;
if(vis[next]) continue;
int dis = point[next].y - point[now].y;
int flag1 = 0, flag2 = 0;
if(point[now].x + dis > 100 || point[next].x + dis > 100) continue;
if(hash[point[now].x+dis][point[now].y] == false ||
hash[point[next].x+dis][point[next].y] == false) continue;
for(int i = next + 1;i <= n;i++)
{
if(vis[i]) continue;
if(point[i].x == point[now].x + dis && point[i].y == point[now].y)
flag1 = i;
if(point[i].x == point[next].x + dis && point[i].y == point[next].y)
flag2 = i;
if(flag1 && flag2) break;
}
if(flag1 && flag2)
{
//printf("now = %d %d %d %d\n",now,next,flag1,flag2);
vis[now] = true;vis[next] = true;vis[flag1] = true;vis[flag2] = true;
dfs(now + 1,cnt + 4);
vis[now] = false;vis[next] = false;vis[flag1] = false;vis[flag2] = false;
}
}
dfs(now + 1,cnt);
}
int main()
{
while(scanf("%d",&n)!= EOF)
{
if(n == -1) break;
memset(hash,0,sizeof(hash));
memset(vis,0,sizeof(vis));
for(int i = 1;i <= n;i++)
{
scanf("%d %d",&point[i].x,&point[i].y);
hash[point[i].x][point[i].y] = 1;
}
sort(point + 1,point + 1 + n,cmp);
ans = 0;
dfs(1,0);
printf("%d\n",ans);
}
return 0;
}