hdu4760Good Firewall
数组模拟就可以了 读的时候可以整数读入
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<queue> 7 #include<cmath> 8 #include<vector> 9 using namespace std; 10 #define LL __int64 11 int len,maxz; 12 LL ip[1050][16][2],pp[40]; 13 int vis[1050],w[1024],di[50],g; 14 char s[50],s1[50],s2[50]; 15 void init() 16 { 17 int i; 18 pp[0] = 1; 19 for(i = 1; i < 32 ; i++) 20 pp[i] = pp[i-1]*2; 21 } 22 void change(int a) 23 { 24 int x[10],o=0,i; 25 while(a) 26 { 27 x[++o] = a%2; 28 a/=2; 29 } 30 for(i = 1; i <= 8-o ; i++) 31 di[++g] = 0; 32 for(i = o ; i>= 1; i--) 33 di[++g] = x[i]; 34 } 35 LL swit(int k,int e) 36 { 37 int i; 38 LL sum=0; 39 if(k==1) 40 for(i = 1 ; i <= g ; i++) 41 sum+=di[i]*pp[32-i]; 42 else 43 { 44 for(i = 1; i <= e ; i++) 45 sum+=di[i]*pp[32-i]; 46 for(i = e+1 ; i <= 32 ; i++) 47 sum+=pp[32-i]; 48 } 49 return sum; 50 } 51 int main() 52 { 53 int m,n,i,j;init(); 54 int a,b,c,d,e; 55 char cc; 56 while(scanf("%c",&cc)!=EOF) 57 { 58 if(cc=='E') 59 { 60 scanf("%d%d",&n,&m); 61 w[n] = m; 62 maxz = max(maxz,n); 63 for(i = 1; i <= m ;i++) 64 { 65 getchar(); 66 scanf("%d.%d.%d.%d/%d",&a,&b,&c,&d,&e); 67 g=0; 68 change(a);change(b);change(c);change(d); 69 ip[n][i][0] = swit(1,0); 70 ip[n][i][1] = swit(2,e); 71 } 72 } 73 else if(cc=='F') 74 { 75 scanf("%d.%d.%d.%d",&a,&b,&c,&d); 76 g=0; 77 change(a);change(b);change(c);change(d); 78 LL fs1 = swit(1,0); 79 scanf("%d.%d.%d.%d",&a,&b,&c,&d); 80 g=0; 81 change(a);change(b);change(c);change(d); 82 LL fs2 = swit(1,0); 83 int flag = 0; 84 for(i = 1 ; i <= maxz ; i++) 85 { 86 int f=0,ff=0; 87 if(vis[i]) continue; 88 for(j = 1; j <= w[i] ; j++) 89 { 90 if(fs1>=ip[i][j][0]&&fs1<=ip[i][j][1]) 91 f = 1; 92 if(fs2>=ip[i][j][0]&&fs2<=ip[i][j][1]) 93 ff = 1; 94 } 95 if(ff&&f) 96 { 97 flag = 1; 98 break; 99 } 100 } 101 if(flag) 102 printf("F\n"); 103 else 104 printf("D\n"); 105 } 106 else 107 { 108 scanf("%d",&n); 109 vis[n] = 1; 110 } 111 gets(s); 112 } 113 return 0; 114 }