zoukankan      html  css  js  c++  java
  • UVa 11100 The Trip, 2007 (题意+贪心)

    题意:有n个包,其中小包可以装到大的包里,包的大小用数字进行表示,求最小的装包数量。

    析:这个题的题意不太好理解,主要是有一句话难懂,意思是让每个最大包里的小包数量的最大值尽量小,所以我们就不能随便输出了,

    我们先求出最少多少包,这个肯定是相同包的的最大数目了,然后输出时用等差输出,这样就能保证题目的要求。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    //#include <unordered_map>
    //#include <unordered_set>
    #define debug() puts("++++");
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e4 + 5;
    const int mod = 2000;
    const int dr[] = {-1, 1, 0, 0};
    const int dc[] = {0, 0, 1, -1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    int a[maxn];
    
    int main(){
        int kase = 0;
        while(scanf("%d", &n) == 1 && n){
            int ans = 1;
            for(int i = 0; i < n; ++i)  scanf("%d", a + i);
            sort(a, a + n);
            int cnt = 1;
            for(int i = 1; i < n; ++i){
                if(a[i] == a[i-1])  ++cnt;
                else cnt = 1;
                ans = max(ans, cnt);
            }
            if(kase)  puts("");
            ++kase;
            printf("%d
    ", ans);
            cnt = 0;
            while(cnt < ans){
                for(int i = cnt; i < n; i += ans)
                    if(i == cnt)  printf("%d", a[i]);
                    else printf(" %d", a[i]);
                printf("
    ");
                ++cnt;
            }
        }
        return 0;
    }
    //
    
  • 相关阅读:
    22_selenium_使用cookie直接登录
    21_无头模式
    自动化测试-设计模式-介绍
    Doorls
    pytest-Allure报告
    pytest-架构1
    pytest-第一次学习梳理
    web测试
    测试-工时评估
    封装pyuic5转换ui文件的脚本
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/6534392.html
Copyright © 2011-2022 走看看