Codeforces 651B Beautiful Paintings【贪心】
题意:
给定序列,重新排序,使严格上升的子序列最多。求这些子序列总长度。
分析:
贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素。
代码:
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1005;
int a[maxn];
int m[maxn];
int main (void)
{
int n;cin>>n;
for(int i = 0; i < n; i++){
cin>>a[i];
}
sort(a, a + n);
int j = 0;
int maxm = 0;
for(int i = 1; i < n; i++){
if(a[j]!=a[i])
a[++j] = a[i];
else{
m[a[i]]++;
maxm = max(maxm, m[a[i]]);
}
}
int cnt, res = 0;
for(int i = 0; i < maxm; i++){
cnt = 0;
for(int k = 0; k <= j; k++){
if(m[a[k]]>=1){
cnt++;
m[a[k]]--;
}
}
if(cnt > 1) res += cnt - 1;
}
cout<<j + res<<endl;
}
Codeforces 651B Beautiful Paintings【贪心】的更多相关文章
- CodeForces 651B Beautiful Paintings 贪心
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- codeforces 651B Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- codeforce 651B Beautiful Paintings
题意:后一个比前一个大就加一,问最大次数. #include<cstdio> #include<cstring> #include<algorithm> #incl ...
- [刷题codeforces]651B/651A
651B Beautiful Paintings 651A Joysticks 点击可查看原题 651B是一个排序题,只不过多了一步去重然后记录个数.每次筛一层,直到全为0.从这个题里学到一个正确姿势 ...
- codeforces 651B B. Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #345 (Div. 2)——B. Beautiful Paintings(贪心求上升序列个数)
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力
B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...
- Codeforces 651 B. Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input stan ...
- codeforces 704B - Ant Man 贪心
codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...
随机推荐
- LN : leetcode 312 Burst Balloons
lc 312 Burst Balloons 312 Burst Balloons Given n balloons, indexed from 0 to n-1. Each balloon is pa ...
- poj3685 Matrix
思路: 二分套二分. 矩阵在每一列上是严格递增的,可以利用这一点进行二分. 实现: #include <cstdio> #include <cmath> #include &l ...
- dede自定义表单放首页出错的解决办法
一.当自定义表单放首页提交的时候跳出这个页面怎么解决 二.解决办法 可能有多个from表单提交出错,也就是代码冲突的意思,只要把代码检查好,from提交不要重复冲突就可以了
- 在JAVA中封装JSONUtils工具类及使用 (转)
import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util. ...
- jQuery 收缩展开效果
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...
- C#筆記--DataGridView使用
1.databingcomplete 当数据源的内容更改时,或者当 DataSource.DataMember 或 BindingContext 属性的值更改时,会引发此事件. 例如,如果要基于内容更 ...
- spring的设计思想
在学习Spring框架的时候, 第一件事情就是分析Spring的设计思想 在学习Spring的时候, 需要先了解耦合和解耦的概念 耦合: 简单来说, 在软件工程当中, 耦合是指对象之间的相互依赖 耦合 ...
- [PyTorch] rnn,lstm,gru中输入输出维度
本文中的RNN泛指LSTM,GRU等等 CNN中和RNN中batchSize的默认位置是不同的. CNN中:batchsize的位置是position 0. RNN中:batchsize的位置是pos ...
- Java格式化CST时间(mysql date类型)
在从mysql导入数据时候,mysql里的日期是格林威治时间,普通格式化不行,这里总结一下格式化格林威治时间的方法: Date date = new Date(); System.out.printl ...
- 基于PHP的微信支付教程
微信支付作为各大移动支付方式之一,本课程只要向大家介绍并使用微信支付的常用功能,进而集合到已有的项目中去,希望各位能够快速上手并掌握实战"干货". 出处至:汇智网 hubwiz. ...