Codeforces Round #154 (Div. 2) : B
一个很简单的题;
方法一:
二分。
代码:
#include<cstdio>
#include<algorithm>
#define maxn 100005
using namespace std; int num[maxn],n; int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
scanf("%d",&n);
for(int i=;i<n;i++)scanf("%d",&num[i]);
sort(num,num+n);
int ans=;
for(int i=;i<n;i++)
{
int x=upper_bound(num,num+n,*num[i])-num-i;
if(ans<x)ans=x;
}
printf("%d\n",n-ans);
return ;
}
方法二:
双端队列;
代码:
#include<cstdio>
#include<algorithm>
#include<queue>
#define maxn 100005
using namespace std; int num[maxn],n;
queue<int>q; int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
scanf("%d",&n);
for(int i=;i<n;i++)scanf("%d",&num[i]);
sort(num,num+n);
int ans=;
for(int i=;i<n;i++)
{
q.push(num[i]);
if(q.front()*<q.back())q.pop();
if(ans<q.size())ans=q.size();
}
printf("%d\n",n-ans);
return ;
}
Codeforces Round #154 (Div. 2) : B的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- android85 短信防火墙
系统收到短信是有广播的,广播中包含了短信的号码和内容 ###短信防火墙 * 系统发送短信广播时,是怎么把短信内容存入广播的,我们就只能怎么取出来 * 如果短信过长,那么发送时会拆分成多条短信发送,那么 ...
- 使用Java辅助类(CountDownLatch、CyclicBarrier、Semaphore)并发编程
在java 1.5中,提供了一些非常有用的辅助类来帮助我们进行并发编程,比如CountDownLatch,CyclicBarrier和Semaphore,今天我们就来学习一下这三个辅助类的用法 一.C ...
- Chapter 5 - How to Detect the Collisions
Chapter 5 - How to Detect the Collisions Our hero can fire bullets now, but the bullets are only vis ...
- PureMVC(JS版)源码解析(十二):Facade类
MVC设计模式的核心元素在PureMVC中体现为Model类.View类和Controller类.为了简化程序开发,PureMVC应用Facade模式. Facade是Model\View\Co ...
- Ⅶ.AngularJS的点点滴滴-- 事件
事件(和js一样有冒泡和捕获) <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2 ...
- Mysql Join语法解析与性能分析详解
一.Join语法概述 join 用于多表中字段之间的联系,语法如下: ... FROM table1 INNER|LEFT|RIGHT JOIN table2 ON conditiona table1 ...
- gulp 前端自动化工具
一开篇 在前端开发的过程中,我们经常会碰到压缩.合并.图片script 等,于是就有了gulp 前端自动化构建工具,它能帮你在前端开发中,节省时间. 1,安装 node.js 因为gulp 构建工具是 ...
- 类似与三元表达式的 json 读取值
需要先在项目中添加 json的dll json 序列里面的key在item.feeType里面必须存在 否则会报 未将对象引用到实例 myDr["feeType"] = Newto ...
- 第二部分 Nhibernate中的类型
NHibernate类型..net类型.数据库字段类型映射关系 因为NHibernate类型和c#数据类型是对应的,所以也分为值类型和引用类型,另外还有几个特殊的类,我们分别介绍: -- 值类型 | ...
- scope的参数范围
Default -- 显示当前文件夹下的:文件和文件夹 FilesOnly--显示当前文件夹下的:文件 Recursive --显示当前文件夹下的:所有文件,包括子文件夹中的文件 RecursiveA ...