hdu 3498(DLX 重复覆盖)
2013-04-08 13:48
411 查看
简单重复覆盖题。。。
[align=left]Problem Description[/align]
sevenzero liked Warcraft very much, but he haven't practiced it for several years after being addicted to algorithms. Now, though he is playing with computer, he nearly losed and only his hero Pit Lord left. sevenzero is angry, he decided to cheat to turn defeat into victory. So he entered "whosyourdaddy", that let Pit Lord kill any hostile unit he damages immediately. As all Warcrafters know, Pit Lord masters a skill called Cleaving Attack and he can damage neighbour units of the unit he attacks. Pit Lord can choice a position to attack to avoid killing partial neighbour units sevenzero don't want to kill. Because sevenzero wants to win as soon as possible, he needs to know the minimum attack times to eliminate all the enemys.
[align=left]Input[/align]
There are several cases. For each case, first line contains two integer N (2 ≤ N ≤ 55) and M (0 ≤ M ≤ N*N),and N is the number of hostile units. Hostile units are numbered from 1 to N. For the subsequent M lines, each line contains two integers A and B, that means A and B are neighbor. Each unit has no more than 4 neighbor units. The input is terminated by EOF.
[align=left]Output[/align]
One line shows the minimum attack times for each case.
[align=left]Sample Input[/align]
5 4
1 2
1 3
2 4
4 5
6 4
1 2
1 3
1 4
4 5
[align=left]Sample Output[/align]
2
3
[align=left]Author[/align]
sevenzero
[align=left]Source[/align]
2010 ACM-ICPC Multi-University Training Contest(7)——Host by HIT
[align=left]Recommend[/align]
zhouzeyong
whosyourdaddy
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1022 Accepted Submission(s): 502[align=left]Problem Description[/align]
sevenzero liked Warcraft very much, but he haven't practiced it for several years after being addicted to algorithms. Now, though he is playing with computer, he nearly losed and only his hero Pit Lord left. sevenzero is angry, he decided to cheat to turn defeat into victory. So he entered "whosyourdaddy", that let Pit Lord kill any hostile unit he damages immediately. As all Warcrafters know, Pit Lord masters a skill called Cleaving Attack and he can damage neighbour units of the unit he attacks. Pit Lord can choice a position to attack to avoid killing partial neighbour units sevenzero don't want to kill. Because sevenzero wants to win as soon as possible, he needs to know the minimum attack times to eliminate all the enemys.
[align=left]Input[/align]
There are several cases. For each case, first line contains two integer N (2 ≤ N ≤ 55) and M (0 ≤ M ≤ N*N),and N is the number of hostile units. Hostile units are numbered from 1 to N. For the subsequent M lines, each line contains two integers A and B, that means A and B are neighbor. Each unit has no more than 4 neighbor units. The input is terminated by EOF.
[align=left]Output[/align]
One line shows the minimum attack times for each case.
[align=left]Sample Input[/align]
5 4
1 2
1 3
2 4
4 5
6 4
1 2
1 3
1 4
4 5
[align=left]Sample Output[/align]
2
3
[align=left]Author[/align]
sevenzero
[align=left]Source[/align]
2010 ACM-ICPC Multi-University Training Contest(7)——Host by HIT
[align=left]Recommend[/align]
zhouzeyong
#include <stdio.h> #include <string.h> #include <iostream> using namespace std; #define N 5000 #define INF 0x3ffffff struct node { int to,next; }edge ; int R ,L ,U ,D ,num ,col ,line ,H ; int head; int n,m; int g[60][60]; int nn,mm; int cnt,pre[60]; int id; int mi; void add_edge(int x,int y) { edge[cnt].to=y; edge[cnt].next=pre[x]; pre[x]=cnt++; } void prepare() { for(int i=0;i<=mm;i++) { num[i]=0; U[i]=i; D[i]=i; R[i]=i+1; L[i+1]=i; } R[mm]=0; L[0]=mm; memset(H,-1,sizeof(H)); } void link(int tn,int tm) { id++; num[line[id]=tm ]++; col[id]=tn; U[D[tm]]=id; D[id]=D[tm]; U[id]=tm; D[tm]=id; if(H[tn]<0) H[tn]=R[id]=L[id]=id; else { L[R[H[tn]]]=id; R[id]=R[ H[tn] ]; L[id]=H[tn]; R[ H[tn] ]=id; } } void build() { id=mm; prepare(); for(int i=1;i<=n;i++) { link(i,i); for(int p=pre[i];p!=-1;p=edge[p].next) { int v=edge[p].to; link(i,v); } } } int h() { int mark[60]; memset(mark,0,sizeof(mark)); int sum=0; for(int i=R[head];i!=head;i=R[i]) { if(mark[i]==0) { sum++; for(int j=D[i];j!=i;j=D[j]) for(int k=R[j];k!=j;k=R[k]) mark[ line[k] ]=1; } } return sum; } void remove(int s) { for(int i=D[s];i!=s;i=D[i]) { L[R[i]]=L[i]; R[L[i]]=R[i]; } } void resume(int s) { for(int i=D[s];i!=s;i=D[i]) L[R[i]]=R[L[i]]=i; } void dfs(int s) { if(s+h()>=mi) return ; if(R[head]==head) { mi=s; return ; } int tmi=INF,tu; for(int i=R[head];i!=head;i=R[i]) if(num[i]<tmi) { tmi=num[i]; tu=i; } for(int i=D[tu];i!=tu;i=D[i]) { remove(i); for(int j=R[i];j!=i;j=R[j]) remove(j); dfs(s+1); for(int j=L[i];j!=i;j=L[j]) resume(j); resume(i); } } int main() { while(scanf("%d%d",&n,&m)!=EOF) { head=cnt=0; memset(pre,-1,sizeof(pre)); for(int i=0;i<m;i++) { int x,y; scanf("%d%d",&x,&y); add_edge(x,y); add_edge(y,x); } nn=0; mm=n; build(); mi=INF; dfs(0); printf("%d\n",mi); } }
相关文章推荐
- [DLX重复覆盖] hdu 3498 whosyourdaddy
- hdu 3498 whosyourdaddy 重复覆盖+DLX 每次攻击i和i的所有邻居,最少攻击多少人才能杀死所有敌人
- HDU 3498 whosyourdaddy DLX重复覆盖
- HDU 3498 whosyourdaddy 重复覆盖 DLX+A*
- hdu - 3498 - whosyourdaddy(重复覆盖DLX)
- HDU 2295.Radar (DLX重复覆盖)
- HDU 2295 Radar(重复覆盖,DLX)
- [DLX重复覆盖] hdu 4735 Little Wish~ lyrical step~
- HDU-5046 Airport(二分+DLX重复覆盖)
- [DLX重复覆盖] hdu 3656 Fire station
- HDU 3656 DLX重复覆盖
- hdu 3957 Street Fighter 重复覆盖+精确覆盖 DLX
- hdu 2295 DLX重复覆盖
- [DLX重复覆盖] hdu 2828 Lamp
- HDU 2828 Lamp(DLX重复覆盖)
- [DLX重复覆盖] hdu 3957 Street Fighter
- HDU 3498 whosyourdaddy (可重复覆盖舞蹈链)
- hdu - 4979 - A simple math problem.(可重复覆盖DLX + 打表)
- HDU 2295 Radar(DLX可重复覆盖)
- HDU 5046 Airport(二分+DLX重复覆盖)