【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 ...
随机推荐
- mfc线程
1.生成线程 方式1. HANDLE hthread; //线程句柄 hthread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)threadFunc,NU ...
- c++学习之:根据GetLastError()返回值获取错误信息
VC中GetLastError()获取错误信息的使用在VC中编写应用程序时,经常需要涉及到错误处理问题.许多函数调用只用TRUE和FALSE来表明函数的运行结果.一旦出现错误,MSDN中往往会指出请用 ...
- QQ邮箱
yourTEXThere
- Linux下mysql备份 恢复
转载自http://blog.chinaunix.net/uid-20577907-id-161611.html 比如我们要备份mysql中已经存在的名为linux的数据库,要用到命令mysqldum ...
- MSM8909+Android5.1.1之系统烧录
1. 安装高通USB驱动 图1 安装成功后,同时按下设备的音量+和音量-按键,且用USB连接到设备上,在设"设备管理器--->端口"下面看到USB虚拟的端口,如下: ...
- .Net分页实现
public partial class _Default : System.Web.UI.Page { private mydbDataContext _context = new mydbData ...
- TortoiseGit中push的使用
https://tortoisegit.org/docs/tortoisegit/tgit-dug-push.html Options Force (May discard known changes ...
- Linux链接库三(C跟C++之间动态库的相互调用)
http://www.cppblog.com/wolf/articles/74928.html http://www.cppblog.com/wolf/articles/77828.html http ...
- Timeout expired超时时间已到. 达到了最大池大小 错误及Max Pool Size设置
此文章非原创,仅为分享.学习!!! 参考数据库链接串: <add key="data" value="server=192.168.1.123; port=3306 ...
- centos vpn
yum install ppp -y cd /usr/local/src wget http://dl.fedoraproject.org/pub/epel/7/x86_64/p/pptpd-1.4. ...