Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分
2 seconds
256 megabytes
standard input
standard output
Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d is some non-negative integer.
Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that.
The first line contains integer n (1 ≤ n ≤ 2·105) — the number of throws of the first team. Then follow n integer numbers — the distances of throws ai (1 ≤ ai ≤ 2·109).
Then follows number m (1 ≤ m ≤ 2·105) — the number of the throws of the second team. Then follow m integer numbers — the distances of throws of bi (1 ≤ bi ≤ 2·109).
Print two numbers in the format a:b — the score that is possible considering the problem conditions where the result of subtraction a - bis maximum. If there are several such scores, find the one in which number a is maximum.
3
1 2 3
2
5 6
9:6
5
6 7 8 9 10
5
1 2 3 4 5
15:10
思路:我怎么zz的写了个二分;
n*3-n小于等于d的个数-m*2-m大于d的个数最大;
显然需要求n小于等于d的个数+m大于d的个数最小;
我是暴力二分,排个序好像可以把二分取消了;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int a[N],b[N],sa,sb;
int l[N<<];
int flag,n,m;
int check(int x)
{
int pos1=upper_bound(a,a+n,x)-a;
int pos2=upper_bound(b,b+m,x)-b;
pos2=m-pos2;
return pos1+pos2;
}
int main()
{
flag=;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]),l[flag++]=a[i];
scanf("%d",&m);
for(int i=;i<m;i++)
scanf("%d",&b[i]),l[flag++]=b[i];
sort(a,a+n);
sort(b,b+m);
l[flag++]=;
l[flag++]=2e9+;
sort(l,l+flag);
flag=unique(l,l+flag)-l;
int minn=inf,ans;
for(int i=;i<flag;i++)
{
int v=check(l[i]);
if(v<minn)
{
minn=v;
ans=l[i];
}
}
int ji=,lu=;
for(int i=;i<n;i++)
if(a[i]<=ans)
ji++;
for(int i=;i<m;i++)
if(b[i]>ans)
lu++;
printf("%d:%d",*n-ji,*m+lu);
return ;
}
Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分的更多相关文章
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball 暴力水题
C. Vasya and Basketball time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball 排序
C. Vasya and Basketball Vasya follows a basketball game and marks the distances from which each te ...
- Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题
B. Vasya and Wrestling 题目连接: http://codeforces.com/contest/493/problem/B Description Vasya has becom ...
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 水
D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 镜面对称 博弈论
D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力水题
A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 博弈
D. Vasya and Chess Vasya decided to learn to play chess. Classic chess doesn't seem interesting to ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力
A. Vasya and Football Vasya has started watching football games. He has learned that for some foul ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football(模拟)
简单题,却犯了两个错误导致WA了多次. 第一是程序容错性不好,没有考虑到输入数据中可能给实际已经罚下场的人再来牌,这种情况在system测试数据里是有的... 二是chronologically这个词 ...
随机推荐
- 去除冗余 – 精简您的CSS样式代码
讲讲常见的一些没有必要使用CSS代码情况,而这些不起作用可以去掉的CSS代码可能是我们经常忽视的.越是对CSS理解不够,越容易出现这些问题. 二.一些常见不必要CSS样式 1.与默认CSS样式一致 我 ...
- PHP最原始的上传文件函数
<?php $upload_file=$_FILES['upload_file']['tmp_name']; $upload_file_name=$_FILES['upload_file'][' ...
- servlet 笔记
Servlet的作用是接收浏览器传给服务端的请求(request),并将服务端处理完的响应(response)返回给用户的浏览器,浏览器和服务端之间通过http协议进行沟通,其过程是浏览器根据用户的选 ...
- SQL Server 2005 日志文件过大处理
由于安装的时候没有计划好空间,默认装在系统盘,而且又没有做自动备份.截断事务日志等,很快LDF文件就达到十几G,或者几十G ,此时就不得不处理了. 备份和计划就不说了,现在就说下怎么把它先删除吧: 1 ...
- ACM第四站————最小生成树(普里姆算法)
对于一个带权的无向连通图,其每个生成树所有边上的权值之和可能不同,我们把所有边上权值之和最小的生成树称为图的最小生成树. 普里姆算法是以其中某一顶点为起点,逐步寻找各个顶点上最小权值的边来构建最小生成 ...
- ACM题目————STL练习之众数问题
描述 所谓众数,就是对于给定的含有N个元素的多重集合,每个元素在S中出现次数最多的成为该元素的重数, 多重集合S重的重数最大的元素成为众数.例如:S={1,2,2,2,3,5},则多重集S的众数是2, ...
- Oracle关闭session锁
select session_id from v$locked_object;//找到锁的sessionId SELECT * FROM v$session //查看该sessionId以及对应的 ...
- java交换两个数字位置
第一种:在main输出,通过反射实现 1 public static void main(String[] args) throws Exception { Integer a = 1; Intege ...
- JS中的call()和apply()方法和bind()
1.方法定义 call方法: 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 说明: call ...
- iOS之地理位置及定位系统 -- 入门笔记
这是因为xcode升级造成的定位权限设置问题.升级xcode6.xcode7以后打开以前xcode5工程,程序不能定位.工程升级到xcode6或xcode7编译时需要iOS8 要自己写授权,不然没权限 ...