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

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;
} 
时间: 2024-08-06 03:46:54

codeforces 493C Vasya and Basketball (枚举+模拟+思维)的相关文章

codeforces 493C Vasya and Basketball(二分)

传送门:点击打开链接 题目大意: 有2个队打篮球,然后告诉你,A队投了N次蓝,分别的距离,B队投了M篮,分别的距离. As we all know, 篮球有个三分线,然后让你找一个三分线出来,使得A队的得分-B队得分最大.差值相同的情况下,找比分最大的. 压线算2分. 解题思路: 假设一个投篮线.在X处 那么很容易 算出每个队的得分情况.(只需要排序 然后二分哪些值是小于等于他的就好了). 那么就枚举投篮线就好,只需要在N+M个数字之间枚举.然后再增加一个0和INF 2条线. 总结一下吧: 打了

CodeForces 354A - Vasya and Robot (简单思维)

题意: 有一个机器人   他有两只手,一只左手一只右手,他面前摆了一排东西,左手只能从最左边拿,右手只能从最右边拿,每个东西有一个重量w[i]  ,   左手拿起这样东西需要消耗 w[i] * l  的能量, 右手拿起这样东西需要消耗w[i] * r 的能量,如果连续使用左手或者右手还需要多消耗 Q1或者Q2的能量,问拿走所有东西所需要消耗的最少能量是多少? 题解: 最后的状态无非就是左边一节为左手拿的,右边一节为右手拿的, 我们只需要枚举分界点,然后看左边右边差了多少个物品就可以知道多少次过载

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 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 does

CodeForces - 837E - Vasya&#39;s Function | Educational Codeforces Round 26

/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f(a, b) = 1 + f(a, b-gcd(a, b)); 求 f(a, b) , a,b <= 1e12 分析: b 每次减 gcd(a, b) 等价于 b/gcd(a,b) 每次减 1 减到什么时候呢,就是 b/gcd(a,b)-k 后 不与 a 互质 可先将 a 质因数分解,b能除就除,不能

Codeforces 837E. Vasya&#39;s Function

http://codeforces.com/problemset/problem/837/E 题意: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)) 输出f(a,b) a=A*gcd(a,b)    b=B*gcd(a,b) 一次递归后,变成了 f(A*gcd(a,b),(B-1)*gcd(a,b)) 若gcd(A,(B-1))=1,那么 这一层递归的gcd(a,b)仍等于上一层递归的gcd(a,b) 也就是说,b-gcd(a,b),有大量的时间减的

HDU 4930 Fighting the Landlords(暴力枚举+模拟)

HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型,如果先手能一步走完,或者一步让后手无法管上,就赢 思路:先枚举出两个人所有可能的牌型的最大值,然后再去判断即可 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct Player { int rank[15]; } p1, p2; int t, h

CodeForces 577C Vasya and Petya&#39;s Game 数学

题意就是给你一个1到n的范围 你每次可以问这个数是否可以被某一个数整除 问你要猜多少数才能确定这个数…… 一开始一点思路也没有 后来查了一下才知道 每个数都可以分为几个质数的整数次幂相乘得到…… 1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include<string.h> 6 #include<string>

Codeforces 97D Robot in Basement bitset+模拟

题目链接:点击打开链接 题意: 每个点有一个机器人(.),下面是一些指令,每次发出指令(一个字母)所有机器人都会执行移动. 当机器人到E点就会离开. 若机器人前方是'#' 或者边界则停留原地.一个方格可以站多个机器人. bitset模拟.. #include <cstdio> #include <cstring> #include <algorithm> #include <bitset> using namespace std; char s[100005

UVA 10881 - Piotr&#39;s Ants【模拟+思维】

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1822 题意:有很多只蚂蚁在一条直线上,每个蚂蚁移动速度都是1,并且有一个初始方向.并且当相邻两个蚂蚁相撞时转向.现在问t时间后各个蚂蚁的位置. 解法:这题的一个致命技巧就是把两只蚂蚁的相撞看作是两只蚂蚁交换穿过对方并且交换蚂蚁的编号.这个是很好理解的,类似于物理的完全弹性碰撞.又由