codeforces 493C Vasya and Basketball(二分)

传送门:点击打开链接

题目大意:

有2个队打篮球,然后告诉你,A队投了N次蓝,分别的距离,B队投了M篮,分别的距离。

As we all know, 篮球有个三分线,然后让你找一个三分线出来,使得A队的得分-B队得分最大。差值相同的情况下,找比分最大的。

压线算2分。

解题思路:

假设一个投篮线。在X处 那么很容易 算出每个队的得分情况。(只需要排序 然后二分哪些值是小于等于他的就好了)。

那么就枚举投篮线就好,只需要在N+M个数字之间枚举。然后再增加一个0和INF 2条线。

总结一下吧:

打了广州之后就已经不搞ACM了,所以好久没写代码,代码真的是越写越丑。读题结束就想到思路的题,写了30分钟。

#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
long long a1[201010],a2[201010];

int main()
{
    long long n,m;
    cin >> n;
    for(long long i = 1;i <= n;i++){
        scanf("%I64d",&a1[i]);
    }
    cin >> m;
    for(long long i = 1;i <= m;i++){
        scanf("%I64d",&a2[i]);
    }
    sort(a1+1,a1+1+n);
    sort(a2+1,a2+1+m);
    long long ans1,ans2,temp1,temp2;
    long long x,y;
    x = upper_bound(a1+1,a1+1+n,0)-a1-1;
    y = upper_bound(a2+1,a2+1+m,0)-a2-1;
    ans1 =  3LL*n-x;
    ans2 =  3LL*m-y;
    for(long long i = 1;i <= n;i++){
        x = upper_bound(a1+1,a1+1+n,a1[i])-a1-1;
        y = upper_bound(a2+1,a2+1+m,a1[i])-a2-1;
        temp1 =  3LL*n-x;
        temp2 =  3LL*m-y;
        if(temp1 - temp2 > ans1-ans2){
            ans1 = temp1;
            ans2 = temp2;
        }
        if(temp1 - temp2 == ans1-ans2){
            if(temp1 > ans1){
                ans1 = temp1;
                ans2 = temp2;
            }
        }
    }
    for(long long i = 1;i <= m;i++){
        x = upper_bound(a1+1,a1+1+n,a2[i])-a1-1;
        y = upper_bound(a2+1,a2+1+m,a2[i])-a2-1;
        temp1 =  3LL*n-x;
        temp2 =  3LL*m-y;
        if(temp1 - temp2 > ans1-ans2){
            ans1 = temp1;
            ans2 = temp2;
        }
        if(temp1 - temp2 == ans1-ans2){
            if(temp1 > ans1){
                ans1 = temp1;
                ans2 = temp2;
            }
        }
    }
    x = upper_bound(a1+1,a1+1+n,0x3f3f3f3f)-a1-1;
    y = upper_bound(a2+1,a2+1+m,0x3f3f3f3f)-a2-1;
    temp1 =  3LL*n-x;
    temp2 =  3LL*m-y;
    if(temp1 - temp2 > ans1-ans2){
        ans1 = temp1;
        ans2 = temp2;
    }
    if(temp1 - temp2 == ans1-ans2){
        if(temp1 > ans1){
            ans1 = temp1;
            ans2 = temp2;
        }
    }
    cout<<ans1<<":"<<ans2<<endl;
    return 0;
}
时间: 2024-10-07 19:21:26

codeforces 493C Vasya and Basketball(二分)的相关文章

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 point

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 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 - 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 374D Inna and Sequence 二分+树状数组

题目链接:点击打开链接 给定n个操作,m长的序列a 下面n个数 if(co>=0)则向字符串添加一个co (开始是空字符串) else 删除字符串中有a的下标的字符 直接在序列上搞,简单模拟 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h&

Codeforces 8D Two Friends 三分+二分+计算几何

题目链接:点击打开链接 题意:点击打开链接 三分house到shop的距离,二分这条斜边到cinema的距离 #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<math.h> #include<set> #include<queue> #include<vector> #include<

Codeforces 837E Vasya&#39;s Function 数论 找规律

题意:定义F(a,0) = 0,F(a,b) = 1 + F(a,b - GCD(a,b).给定 x 和 y (<=1e12)求F(x,y). 题解:a=A*GCD(a,b) b=B*GCD(a,b),那么b-GCD(a,b) = (B-1)*GCD(a,b),如果此时A和B-1依然互质,那么GCD不变下一次还是要执行b-GCD(a,b).那么GCD什么时候才会变化呢?就是说找到一个最小的S,使得(B-S)%T=0其中T是a的任意一个因子.变形得到:B%T=S于是我们知道S=min(B%T).也

Codeforces 837E Vasya&#39;s Function - 数论

Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b. Vasya has two numbers x and y, and he wants to calculate f(x, y).

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),有大量的时间减的