cf493C Vasya and Basketball
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
ab排序
for一遍在a数组枚举d=a[i]-1,这样可以保证最优(因为d=a[i]-1一定比d=a[i]-2优)
然后二分d在b数组中的位置就可以知道有多少个2分多少个3分了
还要考虑d=inf的情况
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m;
int a[200010];
int b[200010];
int now2;
int ans1,ans2,mx,mx2;
int main()
{
n=read();
for(int i=1;i<=n;i++)a[i]=read();
m=read();
for(int j=1;j<=m;j++)b[j]=read();
sort(a+1,a+n+1);
sort(b+1,b+m+1);
int kk=a[1]-1,s1=3*n,s2=0;
for (int i=1;i<=m;i++)if (b[i]>kk)s2+=3;else s2+=2;
mx=s1-s2;mx2=s1;
ans1=s1;ans2=s2;
if (2*n-2*m>mx||2*n-2*m==mx&&2*n>mx2)
{
mx=2*n-2*m;mx2=2*n;
ans1=2*n;ans2=2*m;
}
for (int now=1;now<=n;now++)
{
if (a[now]==a[now-1])continue;
now2=lower_bound(b+1,b+m+1,a[now])-b;
int res1=3*(n-now+1)+2*(now-1),res2=3*(m-now2+1)+2*(now2-1);
if (res1-res2>mx||res1-res2==mx&&res1>mx2)
{
mx=res1-res2;
mx2=res1;
ans1=res1;
ans2=res2;
}
}
printf("%d:%d\n",ans1,ans2);
}
其实因为排序完b数组是递增的,所以可以直接用一个指针来模拟二分
cf493C 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 493C - Vasya and Basketball
C. Vasya and Basketball 题目链接:http://codeforces.com/problemset/problem/493/C time limit per test 2 se ...
- 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 ...
- Vasya and Basketball CodeForces - 493C
Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows ...
- 【Codeforces 493C】Vasya and Basketball
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 枚举三分线(离散后)的位置 然后根据预处理的前缀和,快速算出两个队伍的分数. [代码] #include <bits/stdc++.h& ...
- codeforces 493 C Vasya and Basketball
题意:给出三分线的值d,分别有两支队伍,如果小于等于d,得2分,如果大于d,得三分,问使得a-b最大时的a,b 一看到题目,就想当然的去二分了----啥都没分出来---55555555 后来才知道不能 ...
- Codeforce 493c
H - Vasya and Basketball Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- Codeforces Round #281 (Div. 2)
题目链接:http://codeforces.com/contest/493 A. Vasya and Football Vasya has started watching football gam ...
随机推荐
- JS学习之道:javascript keycode大全
keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter ...
- 读取xml到DataSet中去
XML如下: <?xml version="1.0" encoding="utf-8" ?> <Config> <System&g ...
- android源代码百度网盘分享
转载请标明出处: http://blog.csdn.net/yujun411522/article/details/46334123 本文出自:[yujun411522的博客] 近期在使用Ubunt ...
- UltraEdit环境下,php简单环境配置
1.语法高亮 菜单->视图->查看方式->选中“PHP” 2.自动补全 菜单->高级->配置->自动完成->选中“自动显示自动完成对话框”,字符数选择2-3为 ...
- Java初转型-jdk安装和配置
Java 开发环境配置 > * 下载JDK> * 配置环境变量> * 测试JDK是否安装成功> * 使用 Eclipse 运行第一个 Java 程序 下载JDK 首先我们需要下 ...
- Sql Server 2008清理数据库日志的语句
USE [master]GOALTER DATABASE DNName SET RECOVERY SIMPLE WITH NO_WAITGOALTER DATABASE DNName SET RECO ...
- iOS_SN_百度地图基本使用(1)
上次用了一次百度地图,一直没有记笔记,今天记一笔. 以前没有用过百度地图的时候,听做这方面的朋友说百度地图有不少的坑,但是我做的时候没有遇到太大的坑,主要是要注意官方文档的注意事项,还有配置环境开发中 ...
- SignalR2.0开发实例之——负载均衡
SignalR 2.0作为一个新的而且强大的通信工具,发布博客之后得到了很多人的支持,谢谢...也有人对性能和架设等问题提出了各种质疑..真的很感谢.. 我特意下载了SignalR 2.0的源码硬着头 ...
- SwfUpload及imgareaselect使用方法
1.导入文件 Swfupload相关文件 imgareaselect截取插件相关文件 2.前端html代码 添加一个截取图片的按钮,其他为swf所需的html. <body> <di ...
- Qt5.4静态编译方法
静态编译,就是编译器在编译可执行文件的时候,将可执行文件需要调用的对应动态链接库(.so或.lib)中的部分提取出来,链接到可执行文件中去,使可执行文件在运行的时候不依赖于动态链接库.这样就可以发布单 ...