题目

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. Mysql InnoDB 数据更新/删除导致锁表

    一. 如下对账表数据结构 create table t_cgw_ckjnl ( CNL_CODE ) default ' ' not null comment '通道编码', CNL_PLT_CD ) ...

  2. 函数作用域之闭包与this!

    函数基础友情链接:http://speakingjs.com/es5/ch01.html#_functions 作用域链图解   var x = 1; function foo(){     var ...

  3. 第二章 函数和window对象

    1.什么是函数函数相当于Java中的方法,每一个函数可以做一件事情,但是不属于某一个类 2.使用函数的好处:使代码模块化,功能分工明确,方便调用,思路功能清晰 3.函数的分类:(1)系统函数:系统提前 ...

  4. 把vim插入状态的光标改为竖线

    和终端有关系,如果是Konsole的终端,把下面两行加到.vimrc文件里就可以 let &t_SI = "\<Esc>]50;CursorShape=1\x7" ...

  5. SV randomize

    randomize中的变量只支持2-state的values,不支持4-states. randc类型的变量不能被约束在solve------before的语句中. constraint可以被定义在c ...

  6. 使用addeventlistener为js动态创建的元素添加事件监听

    点击li弹出内容,并且动态添加li之后有效 <button onclick="addFunction()">点我增加</button> <ul> ...

  7. vue的环境配置

    在vue越来越火的情况下,本人也开始加入到大军当中. 首先,列举下我们需要的东西: node.js 环境(npm包管理器) vue-cli 脚手架构建工具 cnpm npm的淘宝镜像 安装node.j ...

  8. [BOZJ2721]樱花

    题目求\(\frac{1}{x}+\frac{1}{y}=\frac{1}{n!}\)已知n, x和y的正整数解的个数 设z=\(n!\) \(\frac{1}{x}+\frac{1}{y}=\fra ...

  9. 转 flowcanvas

    http://blog.sina.com.cn/s/blog_5fb40ceb0102wveq.html Unity 强大的可视化编程插件,Flowcanvas + Nodecanvas 组合(深度修 ...

  10. nyoj308-Substring

    #include<stdio.h> #include<string.h> #include<string> #include<math.h> #incl ...