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

转载于:https://www.cnblogs.com/LyonLys/archive/2012/09/14/hdu_2766_Lyon.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值