【贪心】17.6.1 优雅的序列 题解
2017-06-02 18:57
351 查看
取每一次的lis就可以了
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn = 1e5+5; int n,tot,ans; int a[maxn],b[maxn]; template <class T> inline void read(T &x) { int flag = 1; x = 0; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = (x<<1)+(x<<3)+ch-'0'; ch = getchar(); } x *= flag; } int main() { freopen("grace.in","r",stdin); freopen("grace.out","w",stdout); read(n); for(int i = 1; i <= n; i++) read(a[i]); sort(a+1, a+1+n); for(int i = 1; i <= n; i++) if(a[i] == a[i-1]) b[tot]++; else b[++tot]++; sort(b+1, b+1+tot); for(int i = 1; i <= tot; i++) if(b[i] != b[i-1]) ans += (tot-i)*(b[i]-b[i-1]); printf("%d\n",ans); return 0; }
相关文章推荐
- 贪心探索之 时间序列问题 之 hdu 2037
- LeetCode -- Best Time to Buy and Sell Stock II (贪心策略,差分序列)
- 【HDU】5248-序列变换(贪心+二分)
- 百度之星2015初赛(1)1003 HDOJ5248 序列变换(二分 贪心)
- 51nod 1255 字典序最小的子序列 贪心
- hdoj 5248 序列变换 【贪心 + 二分】
- [贪心 高维前缀和] BZOJ5092. 分割序列
- BZOJ 5092: 分割序列 贪心 高维前缀和
- 646. Maximum Length of Pair Chain 类似与最长子序列但是有简单做法 贪心方法
- 51 nod 1255 字典序最小的子序列(单调栈 贪心)
- 如何优雅地用TensorFlow预测时间序列:TFTS库详细教程
- NOIP模拟题 2016.11.5 [贪心] [坐标离散化] [循环序列LIS]
- SSL2845 2017年11月8日提高组T2 序列操作(贪心,树状数组,差分)
- Hdu 5248 序列变换【二分+贪心】
- poj 1659 Frogs' Neighborhood 度序列可图化 贪心
- 贪心 序列
- BZOJ 1046 [HAOI2007]上升序列 动态规划+贪心
- poj 1936 串(字序列匹配,满足贪心性质)复杂度O(n+m)
- CSU 1350 To Add Which? 给序列增加最少的值使得相邻数差<=D 优先队列+贪心
- 九度OJ 1533 最长上升子序列 (基于贪心和二分查找)