zoukankan      html  css  js  c++  java
  • codeforces 493 C Vasya and Basketball

    题意:给出三分线的值d,分别有两支队伍,如果小于等于d,得2分,如果大于d,得三分,问使得a-b最大时的a,b

    一看到题目,就想当然的去二分了----啥都没分出来---55555555

    后来才知道不能二分,因为随着d的增大,两个队的得分都会逐渐减少,但是两个队伍的得分的差值的单调性却不知道

    是这一篇这样讲的 http://www.cnblogs.com/huangxf/p/4142760.html

    然后就依次枚举d的值,维护一个最大值

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<set>
     9 #include<queue> 
    10 #include<algorithm>  
    11 using namespace std;
    12 
    13 typedef long long LL;
    14 const int INF = (1<<30)-1;
    15 const int mod=1000000007;
    16 const int maxn=1000005;
    17 
    18 int n,m;
    19 int a[maxn],b[maxn],c[maxn];
    20 
    21 int main(){
    22     int cnt=0;
    23     c[++cnt]=0;
    24     scanf("%d",&n);
    25     for(int i=0;i<n;i++) scanf("%d",&a[i]),c[++cnt]=a[i];
    26     scanf("%d",&m);
    27     for(int i=0;i<m;i++) scanf("%d",&b[i]),c[++cnt]=b[i];
    28     
    29     sort(a,a+n);
    30     sort(b,b+m);
    31     sort(c,c+cnt);
    32     int tmp=-INF,L,R;
    33 
    34     int lb,ub;
    35     for(int i=1;i<=cnt;i++){
    36         int x=upper_bound(a,a+n,c[i]) - a;
    37         int y=upper_bound(b,b+m,c[i]) - b;
    38         
    39         lb = x*2 + (n-x)*3;
    40         ub = y*2 + (m-y)*3;
    41         if(lb - ub > tmp){
    42             tmp=lb-ub;
    43             L=lb;R=ub;
    44         }
    45         if(lb - ub == tmp && lb > L) L = lb;
    46     }
    47     printf("%d:%d
    ",L,R);
    48     return 0;
    49 }
    View Code
  • 相关阅读:
    CF1280G Kirchhoff's Current Loss【表达式解析,不等式】
    [AGC040C] Neither AB nor BA
    [AGC040B]Two Contests
    [ARC101E]Ribbons on Tree(容斥,dp)
    [GXOI/GZOI2019]旧词
    [SDOI2015]寻宝游戏
    半平面交初步
    [CF585E]Marbles
    [P5348]密码解锁
    NOIP2018 保卫王国
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4607402.html
Copyright © 2011-2022 走看看