【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 ...
随机推荐
- Android SDK版本和ADT版本
Android SDK版本和ADT版本 Android早期的版本号有点“混乱”,比如Android 2.2对应的ADT版本为ADT-0.9.9而Android 2.3对应的的ADT版本则突然“跃迁 ...
- js css 构建滚动边框
注:预览效果请点击result选项卡,个人认为这种效果非常适合做友情链接. 完整代码 <!DOCTYPE html> <html xmlns="http://www.w3. ...
- android导入项目出现style错误,menu错误
android导入项目出现style错误,menu错误 style //查看 res/values/styles.xml 下的报错点. <style name="AppBaseThem ...
- 网络编程(一)——InetAddress
网络编程(一)--InetAddress InetAddress类在java中代表的是IP地址,它有两个子类分别是Inet4Address和Inet6Address,其中Inet4Address代表的 ...
- BZOJ 3226: [Sdoi2008]校门外的区间
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3226 题意:初始集合S为空.模拟四种集合操作:集合并.交.差.补集并. 思路:区间 ...
- hdu4992 Primitive Roots(所有原根)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4992 题意:给出n,输出n的所有原根. 思路:求出n的一个原根x,那么对于所以的i,i<phi( ...
- <转>“人脉投资”的10条建议
谁都知道人脉很重要,所以有些人非常勤奋的“做人脉”,他们往往会这样做—— 积极的参与各类线下活动,逢人就换名片.加微信. 见到名人或者重要人物必合影,而且他们还会掏出手机来给你看. 逢年过节,给所有他 ...
- MYSQL主键自动增加的配置及auto_increment注意事项
文章一 原文地址: http://ej38.com/showinfo/mysql-202971.html 文章二: 点击转入第二篇文章 在数据库应用,我们经常要用到唯一编号.在MySQL中可通过字 ...
- JavaWeb(一)
Web应用程序开发是目前软件开发领域的三大方向之一. 静态网页与动态网页 静态网页 表现形式:网页的内容是固定的,不会更新: 使用的技术:HTML,CSS 动态网页 表现形式:网页中的内容通过程序动态 ...
- vsftp软链接ln遇到550错误
centos 6.3上新建了vsftp ,用于文件下载使用 ./var/ftp/pub可以匿名登陆下载 .如果想要上传则需要使用密码验证 . 登陆使用的账号是ftpclient ,路径在/home/f ...