UVA11100 The Trip, 2007(贪心)
来源:互联网 发布:死亡天使蘑菇 淘宝 编辑:程序博客网 时间:2024/06/06 10:02
https://acm.bnu.edu.cn/v3/problem_show.php?pid=19518
题解:
这道题就是要这个序列划分成几个字序列,这几个子序列要求严格上升,然后每个序列的元素个数尽量相等。
而且这道题可以排序之后直接搞,可以任意选择数。
那就很好办了,分成子序列的个数其实就是最大的相同元素的个数。
直接输出就好了,开始没理解题意。
代码写的丑,勿喷。
#include<bits/stdc++.h>using namespace std;const int maxn=10005;int n,Len,A[maxn];bool used[maxn];int main() {#ifdef tangge// freopen("11100.out","w",stdout);#endif // tangge int f=0; while(scanf("%d",&n)==1,n) { if(f)printf("\n"); f=1; for(int i=0; i<n; ++i) { scanf("%d",&A[i]); } sort(A,A+n); Len=0; for(int i=0; i<n; ++i) { int now=1; for(int j=i+1; j<n; ++j) { if(A[j]==A[j-1]) { ++now; Len=max(Len,now); } else { i=j-1; break; } } } Len=max(Len,1); printf("%d\n",max(Len,1)); int maxN=n/Len; if(maxN*Len<n)++maxN; memset(used,false,sizeof(used)); for(int i=0; i<n; ++i) { if(used[i])continue; printf("%d",A[i]); used[i]=true; int now=1,last=A[i]; for(int j=i+1; j<n; ++j) { if(used[j])continue; if(now<maxN&&(last^A[j])) { printf(" %d",A[j]); last=A[j]; used[j]=true; ++now; } } printf("\n"); } } return 0;}
1 0
- [贪心]UVA11100 - The Trip, 2007
- UVA11100 The Trip, 2007(贪心)
- uva11100 - The Trip, 2007
- UVA11100- The Trip, 2007
- uva11100 - The Trip, 2007
- uva11100 - The Trip, 2007(旅行2007)
- The Trip, 2007(贪心)
- UVA 11100 The Trip, 2007 (贪心)
- uva 11100 The Trip, 2007(贪心)
- UVA 11100 - The Trip, 2007(贪心)
- Poj 3287 The Trip, 2007 (简单贪心)
- poj 3287 The Trip, 2007_贪心
- uva - 11100 - The Trip, 2007(贪心)
- UVA - 11100 The Trip, 2007(贪心)
- UVA - 11100 The Trip, 2007 贪心
- UVA 11100 The Trip,2007(贪心)
- UVA 111100 The Trip, 2007 贪心 *
- UVA 11100 The Trip, 2007 贪心(输出比较奇葩)
- Android全球定位系统GPS邻近警报-Oak先生
- 不求人!轻松解决米3“内存不足”“无法安装软件”等难题!
- 面向对象的简单计算器C#语言版
- Python进阶【第一篇】socket
- [从零开始unity3D]“五子连珠”游戏实现,网格数组的创建(1)
- UVA11100 The Trip, 2007(贪心)
- Java学习笔记之线程
- HDU5120(几何)
- jQuery 之 (二)事件操作、jq对文档的操作、属性选择器使用
- Python简易图片批量压缩程序
- 强悍的javascript手势库
- [2016ICPC 大连网络预选赛] HDU5874 构造
- C++ getline
- C# RichTextBox 滚动条 滚动到最后一行