题目

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. ASP.NET CORE 2.0 Uses SignalR Technology

    https://www.codeproject.com/Articles/1208322/ASP-NET-CORE-Uses-SignalR-Technology

  2. [macOS] error when brew updating

    I want to update the brew, then run brew update but unluckly, i got these error /usr/local/Library/b ...

  3. Array类型和方法

    var ft = new Array(); var ft = new Array(20); var ft = new Array("1","2","3 ...

  4. vue-cli 2.92版本 没有dev.server.js

    在webpack.dev.conf.js 文件中 //首先 const express = require('express') const app = express() var appData = ...

  5. Vue将px转化为rem适配移动端

    Vue将px转化为rem适配移动端 1.下载lib-flexible我使用的是vue-cli+webpack,所以是通过npm来安装的npm i lib-flexible --save 2.引入lib ...

  6. jw player 配置参数

    Loading the player … //player所在div //具体配置参数 jwplayer(“container”).setup({//通过js调用播放器并安装到指定容器(contain ...

  7. 数据挖掘算法——Close算法

    说明奥:菜鸟的自我学习,可能有错. Close算法原理: 一个频繁闭合项目集的所有闭合子集一定是频繁的,一个非频繁闭合项目集的所有闭合超集一定是非频繁的. close算法是对Apriori算法的改进 ...

  8. phpstudy 安装 Apcahe SSL证书 实现https连接

    摘自:https://jingyan.baidu.com/article/64d05a022e6b57de54f73b51.html Windows phpstudy安装ssl证书教程. 工具/原料 ...

  9. canutils上板测试问题记录

    ltp-ddt运行can_loopback时出错 pan(1881): Must supply a file collection or a command 原因runtest/ddt/can_loo ...

  10. if __name__ == "__main__":

    工欲善其事,必先利其器 # 环境:Python3.6 + win10 # 目录结构: D:\test\ # 目录 ├─ t1.py # 文件 └─ t2.py # 文件 让模块如脚本一样运行 在Pyt ...