首页 > 其他 > 详细

codeforces 493C Vasya and Basketball (枚举+模拟+思维)

时间:2015-02-07 23:02:21      阅读:432      评论:0      收藏:0      [点我收藏+]


C. Vasya and Basketball
time limit per test
2 seconds
memory limit per test
256 megabytes

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 thand meters, where d is somenon-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 ofd. 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 follown integer numbers — the distances of throwsai (1?≤?ai?≤?2·109).

Then follows number m (1?≤?m?≤?2·105) — the number of the throws of the second team. Then followm integer numbers — the distances of throws ofbi (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 subtractiona?-?b is maximum. If there are several such scores, find the one in which numbera is maximum.

Sample test(s)
Input
3
1 2 3
2
5 6
Output
9:6
Input
5
6 7 8 9 10
5
1 2 3 4 5
Output
15:10


题目链接:http://codeforces.com/problemset/problem/493/C


题目大意:有两个队比赛投篮,A队投了n球距离为ai,B队投了m球距离为bi,其中有两分有三分,给一个三分线,使得A队总得分减去B队总得分的值最大,若有多种可能取A队得分最多的那组,输出A队和B队最后的比分


题目分析:先把比分排序,初始都认为两队得的都是两分,设两个变量ab和ba分别表示A比B多1分的次数和B比A多一分的次数(其实就是A和B三分球的次数),模拟更新一下ab和ba的值即可,详细见程序注释


#include <iostream> 
#include <algorithm>
#define ll long long  
using namespace std;  
int const MAX = 200005;  
ll a[MAX], b[MAX], n, m;  

int main()  
{  
    cin >> n;  
    for(int i = 0; i < n; i++) 
        cin >> a[i];  
    cin >> m;  
    for(int i = 0; i < m; i++) 
        cin >> b[i];  
    sort(a, a + n);   
    sort(b, b + m);  
    int j = m - 1;  
    ll x = 0, y = 0, ab = n, ba = m;
    for(int i = n - 1; i >= 0; i--)  
    {  
        //B比A距离远一次则以当前三分线a[i],B比A多一次三分
        while(j >= 0 && a[i] <= b[j]) 
        {
            j--;
            y++;
        }
        //以当前的a[i]做三分线,A的三分次数加1
        x++;  
        //根据差值更新A,B三分球的次数,注意这里的等号不能少!
        //题目要求多组解取A得分最高的那组就体现在这里,如果两次差值
        //相同,那就让A,B都得3分,这样差值不会变,但比2分时的得分高
        if(x - y >= ab - ba)
        { 
            ab = x;
            ba = y;  
        }
    }  
    //如果最后A所能得到的三分次数都比B小那就把所有投篮都当作2分
    //因为要求A的总分减去B的总分最大,在这种情况下如果算上3分
    //显然sumA - sumB的值就会变小,因为sumB大了
    if(ab < ba) 
        ab = ba = 0;  
    //累加上三分的次数及a比b多一分和b比a多一分的次数
    cout << n * 2 + ab << ":" << m * 2 + ba << endl;  
} 


codeforces 493C Vasya and Basketball (枚举+模拟+思维)

原文:http://blog.csdn.net/tc_to_top/article/details/43610791

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!