【二分】Codeforces 706B Interesting drink
2024-10-06 21:46:01
题目链接:
http://codeforces.com/problemset/problem/706/B
题目大意:
n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m(1≤m≤100 000)天,每天有Cj的钱,问每天可以负的起的商店数。
题目思路:
【二分】
排个序,二分。
//
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps (1e-8)
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 100004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int a[N];
bool cmp(int aa,int bb)
{
return aa<bb;
}
int work(int v)
{
int l=,r=n,mid;
while(l<r)
{
mid=(l+r+)>>;
if(v>=a[mid])l=mid;
else r=mid-;
}
return r;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,x,v;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n))
{
for(i=,x=;i<=n;i++)
{
scanf("%d",&a[i]);
x=max(a[i],x);
}
sort(a+,a++n,cmp);
scanf("%d",&m);
for(i=;i<=m;i++)
{
scanf("%d",&v);
if(v>=x)printf("%d\n",n);
else printf("%d\n",work(v));
}
}
return ;
}
/*
// //
*/
最新文章
- ";Installation failed !"; in GUI but not in CLI (/usr/bin/winusb: line 78: 18265 Terminated )
- Hibernate的面试题
- WPF系列:样式
- Unity3D Animation Curve
- WinSCP 连接 Ubuntu 拒绝的问题
- C#常用方法集合
- ubuntu install wine
- HEX格式数据转换成十六进制字符串
- Oracle sql trace
- android上的缓存、缓存算法和缓存框架
- Tomcat内存溢出详解【转载】
- web项目启动,运行方法
- 不同版本的mysql字符集的默认编写
- 用js,css3 做的一个球
- 写给小白的JAVA链接MySQL数据库的步骤(JDBC):
- C# 枚举使用和对应说明获取实例
- Stanford Local 2016 G ";Ground Defense";(线段树)
- java集合框架-List集合ArrayList和LinkedList详解
- 全网最详细的Windows系统里PLSQL Developer 64bit的下载与安装过程(图文详解)
- 消息中间件 ActiveMQ的简单使用
热门文章
- PHP 函数的“引用返回”概念释疑(转)
- Understanding Extension Class Loading--官方
- iOS开发系列之远程控制事件
- Java基础知识强化之IO流笔记16:IO流的概述和分类
- yii自动登陆的验证机制浅析
- codevs 1281 Xn数列 (矩阵乘法)
- C#学习第二天
- Windows上帝模式
- CoreLocation+MapKit系统定位(含坐标以及详细地址)
- Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell&#39;s content view...