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\n", 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("\n");
++cnt;
}
}
return 0;
}
//
UVa 11100 The Trip, 2007 (题意+贪心)的更多相关文章
- UVA 11100 The Trip, 2007 (贪心)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 11100 The Trip, 2007 水题一枚
题目链接:UVA - 11100 题意描述:n个旅行箱,形状相同,尺寸不同,尺寸小的可以放在尺寸大的旅行箱里.现在要求露在最外面的旅行箱的数量最少的同时满足一个旅行箱里放的旅行箱的数量最少.求出这样满 ...
- UVA 11100 The Trip, 2007 贪心(输出比较奇葩)
题意:给出n个包的大小,规定一个大包能装一个小包,问最少能装成几个包. 只要排序,然后取连续出现次数最多的数的那个次数.输出注意需要等距输出. 代码: /* * Author: illuz <i ...
- UVa 11100 - The Trip, 2007 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 11100 The Trip, 2007
今天的教训:做题要用大块的时间来做,上午做一下,做题做到一半就去忙别的事,那么后面再做的时候就无限CE,WA了.因为你很难或者需要很长时间来找回当时的思路. 题意:就像套瓷娃娃一样,有n个包,大小可能 ...
- Uva 11729 Commando War (简单贪心)
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
- uva 1153 顾客是上帝(贪心)
uva 1153 顾客是上帝(贪心) 有n个工作,已知每个工作需要的时间q[i]和截止时间d[i](必须在此前完成),最多能完成多少个工作?工作只能串行完成,第一项任务开始的时间不早于时刻0. 这道题 ...
- The trip(Uva 11100)
题目大意: 给出n个数,要求将其分成最少的递增序列,保证序列最少的同时要使得序列长度的最大值最小. n<=10000 题解: 1.我是直接看着<训练指南>里的中文题面的,lrj似乎 ...
- UVa 11100 旅行2007
https://vjudge.net/problem/UVA-11100 题意: 给定n个正整数,把它们划分成尽量少的严格递增序列,尽量均分. 思路: 因为必须严格递增,所以先统计每个数字出现的次数, ...
随机推荐
- AWS:3. S3
主要内容 1.S3入门 2.S3安全性 对象 权限 访问策略 3.S3实战--BAAS 应用与定价 S3入门 S3概念 S3是simple storge server简单存储服务 相当于网盘,例如百度 ...
- github commit, issue, pull request, project
1 github的提供给用户操作和交流的几个对象 commit, issue, pull request and project 2 commit and commit comment commit就 ...
- ast.literal_eval(jsonStr) json格式字符串转dict 2种方式
json.loads(jsonStr, encoding='utf-8')import ast ast.literal_eval(jsonStr)
- Grunt学习笔记【8】---- grunt-angular-templates插件详解
本文主要讲如何用Grunt打包AngularJS的模板HTML. 一 说明 AngularJS中使用单独HTML模板文件的地方非常多,例如:自定义指令.ng-include.templateUrl等. ...
- 我的Java开发学习之旅------>Java NIO 报java.nio.charset.MalformedInputException: Input length = 1异常
今天在使用Java NIO的Channel和Buffer进行文件操作时候,报了java.nio.charset.MalformedInputException: Input length = 1异常, ...
- Mac root Operation not permitted
在mac下sudo 拷贝和删除文件时提醒Operation not permitted. 网上查了一些资料,需要执行 chflags nouchg /path/to/item 命令. 赶紧照做, ...
- wifi androd 整体框架
1. http://blog.csdn.net/myarrow/article/details/8129607/ 2. http://blog.csdn.net/liuhaomatou/articl ...
- Java for LeetCode 111 Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- Android 普通okhttp、okhttp utils执行 post get请求,文件上传下载、请求图片
public class OKHttpActivity extends Activity implements View.OnClickListener { public static final M ...
- JS 中的面向对象
创建对象的集中常见方式 1 . 使用 Object 或 对象字面量创建对象 2 . 工厂模式创建对象 3 . 构造函数模式创建对象 4 . 原型模式创建对象 1 . 使用 Object 或 对象字面量 ...