Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分
題目連接:
http://codeforces.com/contest/493/problem/C
Description
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.
Input
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).
Output
Print two numbers in the format a:b — the score that is possible considering the problem conditions where the result of subtraction a?-?b is maximum. If there are several such scores, find the one in which number a is maximum.
Sample Input
3
1 2 3
2
5 6
Sample Output
9:6
Hint
題意
A隊在n個距離位置投進了籃球,B隊在m個位置。
現在讓你來劃3分線,然后使得A隊分數減去B隊分數最大。
題解:
暴力枚舉三分線,肯定三分線就n+m+4種可能,都暴力枚舉一邊,然后對于每一個隊伍,我二分找到有多少個二分球,和多少個三分球就好了
代碼
#include<bits/stdc++.h> using namespace std; const int maxn = 2e5+7; int n,m; int a[maxn],b[maxn]; int Ans=-1e9,Ans2,Ans3; void update(int x,int y,int z) {if(Ans<x)Ans=x,Ans2=y,Ans3=z;if(Ans==x&&y>Ans2)Ans=x,Ans2=y,Ans3=z; } void get(int x) {int l=0,r=m,ans=1;while(l<=r){int mid=(l+r)/2;if(b[mid]<=x)ans=mid,l=mid+1;else r=mid-1;}int l2=0,r2=n,ans2=1;while(l2<=r2){int mid=(l2+r2)/2;if(a[mid]<=x)ans2=mid,l2=mid+1;else r2=mid-1;}update(ans2*2+(n-ans2)*3-ans*2-(m-ans)*3,ans2*2+(n-ans2)*3,ans*2+(m-ans)*3); } int main() {scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);scanf("%d",&m);for(int i=1;i<=m;i++)scanf("%d",&b[i]);sort(a+1,a+1+n);sort(b+1,b+1+m);update(2*n-2*m,2*n,2*m);update(3*n-3*m,3*n,3*m);for(int i=1;i<=n;i++)get(a[i]);get(a[1]-1);get(a[n]+1);for(int i=1;i<=m;i++)get(b[i]);get(b[1]-1);get(b[m]+1);printf("%d:%d\n",Ans2,Ans3); }轉載于:https://www.cnblogs.com/qscqesze/p/5844267.html
總結
以上是生活随笔為你收集整理的Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Retrofit 2使用要点梳理:小白进
- 下一篇: lower_bound和upper_bo