标签:
1 /* 2 pro:2015年百度之星程序设计大赛 - 资格赛:IP聚合 3 ID:forever95 4 Date:2015-5-25 5 */ 6 //事实证明C++就是一坨屎 7 #include <iostream> 8 #include <string> 9 #include <cstdio> 10 #include <cstdlib> 11 #include <istream> 12 #include <algorithm> 13 #define M 1000 + 10 14 using namespace std; 15 class IP 16 { 17 private: 18 int a,b,c,d; 19 public: 20 IP() {} 21 void setabcd(int aa,int bb,int cc,int dd) 22 { 23 a = aa; 24 b = bb; 25 c = cc; 26 d = dd; 27 } 28 int showa() 29 { 30 return a; 31 } 32 int showb() 33 { 34 return b; 35 } 36 int showc() 37 { 38 return c; 39 } 40 int showd() 41 { 42 return d; 43 } 44 }; 45 class SubnetMask 46 { 47 private: 48 int A,B,C,D; 49 public: 50 SubnetMask() {} 51 void setABCD(int aa,int bb,int cc,int dd) 52 { 53 A = aa; 54 B = bb; 55 C = cc; 56 D = dd; 57 } 58 int showA() 59 { 60 return A; 61 } 62 int showB() 63 { 64 return B; 65 } 66 int showC() 67 { 68 return C; 69 } 70 int showD() 71 { 72 return D; 73 } 74 }; 75 class code 76 { 77 private: 78 int A,B,C,D; 79 public: 80 code() {} 81 void setABCD(int aa,int bb,int cc,int dd) 82 { 83 A = aa; 84 B = bb; 85 C = cc; 86 D = dd; 87 } 88 friend code operator!=(code &a,code &b); 89 int showA() 90 { 91 return A; 92 } 93 int showB() 94 { 95 return B; 96 } 97 int showC() 98 { 99 return C; 100 } 101 int showD() 102 { 103 return D; 104 } 105 }; 106 bool cmp(code op1,code op2) 107 { 108 if(op1.showA() != op2.showA()) return op1.showA() > op2.showA(); 109 if(op1.showB() != op2.showB()) return op1.showB() > op2.showB(); 110 if(op1.showC() != op2.showC()) return op1.showC() > op2.showC(); 111 if(op1.showD() != op2.showD()) return op1.showD() > op2.showD(); 112 } 113 int main() 114 { 115 //freopen("in.txt","r",stdin); 116 int t; 117 scanf("%d",&t); 118 for(int k = 1; k <= t; k ++) 119 { 120 IP op1[M]; 121 SubnetMask op2[M]; 122 int n,m; 123 scanf("%d%d",&n,&m); 124 for(int i = 0; i < n; i ++) 125 { 126 int aa,bb,cc,dd; 127 scanf("%d.%d.%d.%d",&aa,&bb,&cc,&dd); 128 op1[i].setabcd(aa,bb,cc,dd); 129 } 130 for(int i = 0; i < m; i ++) 131 { 132 int aa,bb,cc,dd; 133 scanf("%d.%d.%d.%d",&aa,&bb,&cc,&dd); 134 op2[i].setABCD(aa,bb,cc,dd); 135 } 136 printf("Case #%d:\n",k); 137 for(int i = 0; i < m; i ++) 138 { 139 code op3[M]; 140 for(int j = 0; j < n; j ++) 141 { 142 int aa,bb,cc,dd; 143 aa = op1[j].showa() & op2[i].showA(); 144 bb = op1[j].showb() & op2[i].showB(); 145 cc = op1[j].showc() & op2[i].showC(); 146 dd = op1[j].showd() & op2[i].showD(); 147 op3[j].setABCD(aa,bb,cc,dd); 148 } 149 sort(op3,op3 + n,cmp); 150 int cnt = 1; 151 for(int j = 1; j < n; j ++) 152 { 153 if(op3[j].showA() == op3[j - 1].showA() && op3[j].showB() == op3[j - 1].showB() && op3[j].showC() == op3[j - 1].showC() && op3[j].showD() == op3[j - 1].showD()) continue; 154 else cnt ++; 155 } 156 printf("%d\n",cnt); 157 // for(int j = 0; j < n; j ++) 158 // printf("%d.%d.%d.%d\n",op3[j].showA(),op3[j].showB(),op3[j].showC(),op3[j].showD()); 159 // printf("\n"); 160 } 161 } 162 return 0; 163 }
标签:
原文地址:http://www.cnblogs.com/zouqihan/p/4528632.html