hdu 2766 Equilibrium Mobile
http://acm.hdu.edu.cn/showproblem.php?pid=2766
不知道算是什么题,应该是排序题吧。。。。
直接将weight乘以2^depth,然后统计相同的个数最多有多少个,用总数减去统计出来的个数就是答案了!
AC代码:
View Code
1 /* 2 Auther: Lyon 3 Problem: hdu 2766 4 */ 5 6 #include <cstdio> 7 #include <iostream> 8 #include <cstring> 9 #include <cassert> 10 #include <algorithm> 11 #include <map> 12 #include <string> 13 #include <vector> 14 15 using namespace std; 16 typedef __int64 ll; 17 typedef vector<int> vi; 18 typedef vector<ll> vll; 19 20 string buf; 21 vll weight; 22 23 int deal(){ 24 weight.clear(); 25 cin >> buf; 26 27 int depth = 0; 28 ll tmp; 29 30 for (string::iterator ii = buf.begin(); ii != buf.end(); ii++){ 31 switch (*ii){ 32 case '[': 33 { 34 depth++; 35 }break; 36 case ']': 37 { 38 depth--; 39 }break; 40 case ',':break; 41 default: 42 { 43 tmp = 0; 44 while ('0' <= *ii && *ii <= '9') tmp = tmp * 10 + *ii - '0', ii++; 45 ii--; 46 //printf("tmp %d\n", tmp); 47 weight.push_back(tmp << depth); 48 } 49 } 50 } 51 52 sort(weight.begin(), weight.end()); 53 54 int len = weight.size(); 55 int best = 0, cur = 1; 56 57 weight.push_back(-1); 58 for (int i = 0; i < len; i++){ 59 if (weight[i + 1] != weight[i]){ 60 best = max(best, cur); 61 cur = 1; 62 } 63 else cur++; 64 } 65 66 return len - best; 67 } 68 69 int main(){ 70 int T; 71 72 //freopen("in", "r", stdin); 73 scanf("%d", &T); 74 while (T--){ 75 cout << deal() << endl; 76 } 77 78 return 0; 79 }
一开始看错了下面这句话:
You may substitute any weight by any (possibly non-integer) weight.
从而我引申出一个变形,就是要求改了以后的数也必须是整数,这是变式的代码:
View Code
这时对于数据:[[[1,1],1],[1,1]],输出应该是3。
另外这题还有一个特别坑的地方,10^9打成109了。。。。搞到我一直wa。。。。
——written by Lyon