hdu4476水题

一个多月没刷题了,找了道水题玩玩。。。

做法很简单。最后的结果一定是在N+1到2N之间的,因为最好的情况就是所有的绳子一样长;最坏的情况就是全都不一样长(此时把最小的那根平均切,其余的切出那个长度即可)。所以,最优解一定是有一种长度的绳子被均切,枚举这个即可。

/*
 * hdu4476/win.cpp
 * Created on: 2013-1-3
 * Author    : ben
 */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
const int MAXN = 100100;
int nums[MAXN];
float data[MAXN];

int main() {
#ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
#endif
    int T, N, ans, m;
    scanf("%d", &T);
    while(T--) {
        memset(nums, 0, sizeof(nums));
        ans = 0;
        set<int> S;
        scanf("%d", &N);
        for(int i = 0; i < N; i++) {
            scanf("%d", &m);
            nums[m]++;
            S.insert(m);
            data[i] = m;
        }
        set<int>::iterator it = S.begin();
        sort(data, data + N);
        while(it != S.end()) {
            int a = *it;
            int temp = N + nums[a];
            temp -= (int)(lower_bound(data, data + N, a / 2.0) - data);
            if(temp > ans) {
                ans = temp;
            }
            it++;
        }
        printf("%d\n", ans);
    }
    return 0;
}

 

posted @ 2013-01-03 22:38  moonbay  阅读(184)  评论(0编辑  收藏  举报