HDU 4462 Scaring the Birds
枚举题。
最多只有10个vacant,所以把(1<<k)中使用vacant的情况都枚举出来找最小值就可以了。
具体看代码,不解释。
1 #include<stdio.h> 2 #include<iostream> 3 using namespace std; 4 5 #include<math.h> 6 #include<stdlib.h> 7 #include<algorithm> 8 #include<string> 9 #include<string.h> 10 #include<map> 11 #include<queue> 12 #define repA(p,q,i) for(int (i)=(p); (i)!=(q); ++(i) ) 13 #define repD(p,q,i) for(int (i)=(p); (i)!=(q); --(i) ) 14 #define repAE(p,q,i) for(int (i)=(p); (i)<=(q); ++(i) ) 15 #define repDE(p,q,i) for(int (i)=(p); (i)>=(q); --(i) ) 16 #define range 52 17 #define maxn 0x3f3f3f3f 18 19 struct node{ 20 int x,y,r; 21 }; 22 23 node vacant[11]; 24 int confirm[range][range]; 25 int n,k,LIM; 26 27 void change(int loc); 28 bool solve(int num, int &here); 29 30 int main() 31 { 32 while( scanf("%d",&n) != EOF ) 33 { 34 if(n==0) break; 35 repAE(1,n,i) 36 repAE(1,n,j) 37 confirm[i][j]=1; 38 scanf("%d",&k); 39 LIM = (1<<k); 40 repA(0,k,i) 41 { 42 scanf("%d%d",&vacant[i].x,&vacant[i].y); 43 confirm[vacant[i].x][vacant[i].y] = -1; 44 } 45 repA(0,k,i) 46 scanf("%d",&vacant[i].r); 47 48 int used = maxn ; 49 int here; 50 repA(0,LIM,num) 51 { 52 if( solve(num, here) ) 53 if( here < used ) 54 used = here; 55 } 56 57 if(used == maxn) printf("-1\n"); 58 else printf("%d\n",used); 59 } 60 return 0; 61 } 62 63 bool solve(int num, int &here) 64 { 65 here=0; 66 repAE(1,n,i) 67 repAE(1,n,j) 68 if(confirm[i][j] != -1) 69 confirm[i][j] = 1; 70 71 repA(0,k,i) 72 { 73 if(num & (1<<i) ) 74 { 75 change(i); 76 ++here; 77 } 78 } 79 80 repAE(1,n,i) 81 repAE(1,n,j) 82 if(confirm[i][j] > 0) 83 return false; 84 85 return true; 86 } 87 88 void change(int loc) 89 { 90 int x = vacant[loc].x; 91 int y = vacant[loc].y; 92 int r = vacant[loc].r; 93 94 int hang,lie,dis; 95 for(hang=x; hang>0&&hang>=x-r; --hang) 96 { 97 dis = r - abs(hang - x) ; 98 for(lie=max(1,y-dis); lie<=min(n,y+dis); ++lie) 99 if(confirm[hang][lie] > 0) 100 confirm[hang][lie] = 0; 101 } 102 for(hang=x+1; hang<=n&&hang<=x+r; ++hang) 103 { 104 dis = r - abs(hang - x) ; 105 for(lie=max(1,y-dis); lie<=min(n,y+dis); ++lie) 106 if(confirm[hang][lie] > 0) 107 confirm[hang][lie] = 0; 108 } 109 return ; 110 }
To Be The Best Of Yourself