zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    113.dynamic_cast 虚函数 通过子类初始化的父类转化为子类类型
    112.虚函数强化
    111.final与override
    110.纯虚函数
    109.虚函数与析构构造
    custom-ubuntu-server-iso
    定制ubuntu的时候修改proseed
    centos使用U盘做启动盘
    fio的配置使用
    持续运行一个命令-并且将结果输出到文本
  • 原文地址:https://www.cnblogs.com/moonbay/p/2843443.html
Copyright © 2011-2022 走看看