【CodeForces 651B】Beautiful Paintings 排序+贪心
题目大意:
给定集合,对于任意一个的排列,记,求。
很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加。
直接暴力需要。
但是可以进行优化。
设有个,将个数从小到大排序,记为长度为的数组。
则答案为
于是可以优化到。
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
const int T=1001;
int n;
int a[T],len;
inline int read(void)
{
int x=0; char c=getchar();
for (;!isdigit(c);c=getchar());
for (;isdigit(c);c=getchar()) x=x*10+c-'0';
return x;
}
int main(void)
{
n=read();
for (int i=1;i<=n;i++) a[read()]++;
printf("%d\n",n-*max_element(a,a+T));
return 0;
}
【CodeForces 651B】Beautiful Paintings 排序+贪心的更多相关文章
- Codeforces 651B Beautiful Paintings【贪心】
题意: 给定序列,重新排序,使严格上升的子序列最多.求这些子序列总长度. 分析: 贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素. 代码: #include<iost ...
- codeforces 651B Beautiful Paintings
B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...
- CodeForces 651B Beautiful Paintings 贪心
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- 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 ...
- 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 题目连接: 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 ...
随机推荐
- Java CSV操作(导出和导入)
Java CSV操作(导出和导入) CSV是逗号分隔文件(Comma Separated Values)的首字母英文缩写,是一种用来存储数据的纯文本格式,通常用于电子表格或数据库软件.在 CSV文件 ...
- iptraf:TCP/UDP网络监控工具
原文:http://www.unixmen.com/iptraf-tcpudp-network-monitoring-utility/ 作者: Enock Seth Nyamador 译文:LCTT ...
- 在JSP页面中输出完整的时间
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- 。JavaSE------初识Java
我的老师告诉我,命运眷顾有志者,天道酬勤. 有时在梦里幻想的再多终究也只是梦, 不如脚踏实地一步步往前走来的踏实. ------------------------------------------ ...
- oracle默认管理员的帐号和密码以及密码修改和解除锁定
安装 ORACLE 时,若没有为下列用户重设密码,则其默认密码如下: 用户名 / 密码 登录身份 说明 sys/change_on_install SYSDBA 或 SYSOPER 不能以 NORMA ...
- 06_在web项目中集成Spring
在web项目中集成Spring 一.使用Servlet进行集成测试 1.直接在Servlet 加载Spring 配置文件 ApplicationContext applicationContext = ...
- div相对浏览器移动
<% String path = request.getContextPath();%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...
- 即时定位与地图构建SLAM(Simultaneous Localization and Mapping)
SLAM 即时定位与地图构建SLAM(Simultaneous Localization and Mapping) 参考链接: 视觉SLAM漫谈,http://www.cnblogs.com/gaox ...
- hnoi 2016 省选总结
感觉省选好难的说...反正我数据结构太垃圾正解想到了也打不出来打一打暴力就滚粗了! DAY1 0+20+30 DAY2 60-20+0+60 最后170-20分,暴力分还是没有拿全! 然而这次是给了5 ...
- 转 iOS和android游戏纹理优化和内存优化(cocos2d-x)
iOS和android游戏纹理优化和内存优化(cocos2d-x) (未完成) 1.2d游戏最占内存的无疑是图片资源. 2.cocos2d-x不同平台读取纹理的机制不同.ios下面使用CGImage, ...