题目

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2674

题意

n个正整数,尽量均匀地把它们分成严格递增序列。要求序列个数最小

思路

明显,序列个数就是出现最多次的正整数的次数。接下来只要循环着由小到大把数字放进各个序列中就可以了。

感想:

读了好几遍都没读懂题目“While maintaining the minimal number of pieces you are also to minimize the total number of bags in any one piece that must be carried”

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<int, int> MyPair;
const int MAXN = 1e4 + ;
const int MAXA = 1e6 + ;
MyPair a[MAXN];
int cnt[MAXA];
int cap[MAXA]; int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int T, n;
for (int ti = ;cin>>n && n; ti++) {
memset(cnt, , sizeof cnt);
for (int i = ; i < n; i++) {
int tmp;
cin >> tmp;
cnt[tmp] ++;
}
int ans = ;
int newn = ;
for (int i = ; i < MAXA; i++) {
ans = max(ans, cnt[i]);
}
int cap_all = (n + ans - ) / ans;
for (int i = ; i <= ans; i++) {
cap[i] = cap_all;
}
int cid = ;
int cidnow = ;
for (int i = ; i < MAXA; i++) {
ans = max(ans, cnt[i]);
while (cap[cid] == ) {
cid++;
}
while (cnt[i]) {
a[newn].first = cidnow;
a[newn].second = i;
newn++;
cnt[i]--;
cap[cidnow]--;
cidnow=(cidnow - cid + ) % (ans - cid) + cid;
}
}
sort(a, a + n);
if (ti > )cout << endl;
cout << ans << endl;
for (int i = ; i < n; i++) {
if (i && a[i].first != a[i - ].first)cout << endl;
else if (i)cout << " ";
cout << a[i].second;
}
cout << endl;
} return ;
}

UVa 11100 - The Trip, 2007 难度: 0的更多相关文章

  1. UVA 11100 The Trip, 2007 水题一枚

    题目链接:UVA - 11100 题意描述:n个旅行箱,形状相同,尺寸不同,尺寸小的可以放在尺寸大的旅行箱里.现在要求露在最外面的旅行箱的数量最少的同时满足一个旅行箱里放的旅行箱的数量最少.求出这样满 ...

  2. UVA 11100 The Trip, 2007 (贪心)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  3. UVA 11100 The Trip, 2007 贪心(输出比较奇葩)

    题意:给出n个包的大小,规定一个大包能装一个小包,问最少能装成几个包. 只要排序,然后取连续出现次数最多的数的那个次数.输出注意需要等距输出. 代码: /* * Author: illuz <i ...

  4. UVa 11100 The Trip, 2007 (题意+贪心)

    题意:有n个包,其中小包可以装到大的包里,包的大小用数字进行表示,求最小的装包数量. 析:这个题的题意不太好理解,主要是有一句话难懂,意思是让每个最大包里的小包数量的最大值尽量小,所以我们就不能随便输 ...

  5. UVa 11100 The Trip, 2007

    今天的教训:做题要用大块的时间来做,上午做一下,做题做到一半就去忙别的事,那么后面再做的时候就无限CE,WA了.因为你很难或者需要很长时间来找回当时的思路. 题意:就像套瓷娃娃一样,有n个包,大小可能 ...

  6. UVa LA 4636 Cubist Artwork 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  7. UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  8. UVa 10970 - Big Chocolate 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  9. Uva 12124 Uva Live 3971 - Assemble 二分, 判断器, g++不用map.size() 难度:0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

随机推荐

  1. random函数的使用

    random作为随机函数用处很多,在Python里面也经常使用,特别是处理一些随机事件的时候,特别好用! 废话不多说,直接看下面的例子: random.randomrandom.random()   ...

  2. Parallels Desktop 重装系统

    安装教程,大家可以在网上找找 现在我想重装系统,怎么弄呢? 1.~/Documents/Parallels 目录下那个PVM后缀的文件直接删除 2.重装找开虚拟机,会弹出一个框,说找不到系统,点击删除 ...

  3. 关于SLG的产品市场判断

    SLG游戏是我自己主攻的未来产品方向,以下几个板块是我自己想着力挖掘的用户艺术: 1)经营能力(包括资源的规划,调配,成长性预期,以及投产比如何向用户选择向最大化) 2)统筹能力(包括自我资源的有效整 ...

  4. CentOS 7 通过SQLmap进行SQL注入

    安装SQLmap: IP:192.168.94.11 渗透测试演练系统DVWA: IP:192.168.94.111 通过SQLmap检测SQL注入漏洞 : 1.安装SQLmap漏洞查看工具 2.安装 ...

  5. java 知识点

    1. java泛型 避免编译错误 (ArrayList定义时候)    避免强制类型装换 2 多态的体现 实现多态主要有以下三种方式:1. 接口实现 2. 继承父类重写方法 3. 同一类中进行方法重载 ...

  6. RocketMQ使用笔记

    apache rocketmq document : http://rocketmq.apache.org/community/ rocketmq 工具下载地址:https://github.com/ ...

  7. nginx-相关功能分析 第四章

    # Nginx服务器的rewrite.全局变量.重定向和防盗链相关功能 一:Nginx 后端服务器组的配置: 1.upstream: 用于定义可由proxy_pass,fastcgi_pass,uws ...

  8. pandas之时间序列

    Pandas中提供了许多用来处理时间格式文本的方法,包括按不同方法生成一个时间序列,修改时间的格式,重采样等等. 按不同的方法生成时间序列 In [7]: import pandas as pd # ...

  9. makefile中的patsubst函数有何作用?

    答:这是个模式替换函数,格式为: $(patsubst <pattern>,<replacement>,<text>) 查找text中的单词,如果匹配pattern ...

  10. Kaggel比赛 : [Give Me Some Credit]

    通过预测在未来两年内某人将经历财务困境的可能性,改善信用评分的状态. Description 银行在市场经济中扮演着至关重要的角色.他们决定谁可以获得融资,以及什么条件,可以做出或破坏投资决策.为了让 ...