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这个词 ...
随机推荐
- 【python cookbook】【数据结构与算法】2 从任意长度的可迭代对象中分解元素
从某个可迭代对象中分解出N个元素,但是可迭代对象的长度可能超过N,会出现“分解值过多”的异常: 使用“*表达式”来解决该问题: Python 3.4.3 (v3.4.3:9b73f1c3e601, F ...
- 161027、Java 中的 12 大要素及其他因素
对于许多人来说,"原生云"和"应用程序的12要素"是同义词.本文的目的是说有很多的原生云只坚持了最初的12个因素.在大多数情况下,Java 能胜任这一任务.在本 ...
- DirectoryInfo类
DirectoryInfo类和Directory类之间的关系与FileInfo类和File类之间的关系十分类似.下面介绍一下DirectoryInfo类的常用属性. DirectoryInfo类的常用 ...
- SQL Server 数据库中关于死锁的分析
SQL Server数据库发生死锁时不会像Oracle那样自动生成一个跟踪文件.有时可以在[管理]->[当前活动] 里看到阻塞信息(有时SQL Server企业管理器会因为锁太多而没有响应). ...
- 【Pro ASP.NET MVC 3 Framework】.学习笔记.6.SportsStore:导航
在之前的章节,偶们设置了核心的基础设施,现在我们将使用基础设计添加关键特性,你将会看到投资是如何回报的.我们能够很简单很容易地添加重要的面向客户的特性.沿途,你也会看到一些MVC框架提供的附加的特性. ...
- mysql转换引擎的方法
有很多方法可以将表的存储引擎转换成另外一种引擎,每种方法都各有优缺点: A:alter table 将表从一个引擎直接改为另外一个引擎最简单的办法 alter table tb_name engine ...
- Bellman-Ford 算法及其优化
Bellman-Ford 算法及其优化 转自:http://hi.baidu.com/jzlikewei/blog/item/94db7950f96f995a1038c2cd.html Bellman ...
- 算法心得2:关于k个最小和问题的思考
问题描述如下: 有k个整数数组,各包含k个元素.在每个数组中取一个元素加起来,可以得到k^k个和.求这些和中最小的k个值(重复计算的算多次). 如果同时考虑这k个数组的取值情况,其复杂程度不言而喻,并 ...
- hdoj4906 Our happy ending(2014 Multi-University Training Contest 4)
对于一个定长(size = n)的数列a, 若其存在“位置相关”的子集(含空集)使得该子集所有元素之和为k,那么将数列a计数. 其中数列a中任一元素a[i]在[0, l]内自由取值. 数据条件0≤n, ...
- DailyReport自动保存工具
PS:自己初学C#,SharePoint时做的一个小tool. Friday, November 28, 2014 这个tool编译出来以后可以把部门的daily report保存到本地,数据库,和 ...