zoukankan      html  css  js  c++  java
  • Codeforces Round #281 (Div. 2) C. Vasya and Basketball

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

    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 - bis maximum. If there are several such scores, find the one in which number a 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

     枚举二分

     1 #include <cstdio>
     2 #include <vector>
     3 #include <cstring>
     4 #include <functional>
     5 #include <algorithm>
     6 #include <math.h>
     7 #include <bitset>
     8 #include <set>
     9 #include <queue>
    10 #include <iostream>
    11 #include <string>
    12 #include <sstream>
    13 #include <stack>
    14 #include <complex>
    15 #include <numeric>
    16 #include <map>
    17 #include <time.h>
    18 using namespace std;
    19 int a[200010],b[200010];
    20 
    21 bool cmp(pair<int ,int > p1,pair<int ,int > p2)
    22 {
    23     if (p1.first - p1.second == p2.first - p2.second) return p1.first < p2.first;
    24     return p1.first - p1.second < p2.first - p2.second;
    25 }
    26 int main()
    27 {
    28     int  n,m;
    29     vector<int> v;
    30     cin >> n ;
    31     for (int i = 0;i < n; ++i)
    32         cin >> a[i],v.push_back(a[i]);
    33     cin >> m;
    34     for (int i = 0;i < m; ++ i)
    35         cin >> b[i],v.push_back(b[i]);
    36     sort(a,a+n);
    37     sort(b,b+m);
    38     pair <int,int>  res = make_pair(3*n,3*m);
    39     sort(v.begin(),v.end());
    40     v.erase(unique(v.begin(),v.end()),v.end());
    41     int pa = 0,pbb = 0,ans;
    42     for (int i = 0;i < v.size(); ++ i) {
    43         while (pa < n && a[pa] == v[i]) pa ++;
    44         while (pbb < m && b[pbb] == v[i]) pbb ++;
    45         res = max(res,make_pair(3*n-pa,3*m-pbb),cmp);
    46     }
    47     printf("%d:%d
    ",res.first,res.second);
    48     return 0;
    49 }
    View Code
     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 typedef long long LL;
     5 const int maxn = 2e5 + 10;
     6 #define rep(i,a,b) for(int i=(a);i<=(b);i++)
     7 
     8 LL A[maxn], B[maxn];
     9 int main() {
    10     LL n, m;
    11     while(cin >> n) {
    12         for(int i = 1; i <= n; ++i)
    13             cin >> A[i];
    14         cin >> m;
    15         for(int i = 1; i <= m; ++i)
    16             cin >> B[i];
    17         sort(A + 1, A + 1 + n);
    18         sort(B + 1, B + 1 + m);
    19         LL a = 0, b = 0, s = INT_MIN, x;
    20         LL res1 = 0, res2 = 0;
    21         A[n + 1] = 2e9 + 7;
    22         for(LL i = 1; i <= n + 1; i++) {
    23             a = 2 * (i - 1) + 3 * (n - i + 1);
    24             if(i > 1 && A[i] == A[i - 1] && i != n + 1)continue;
    25             x = lower_bound(B + 1, B + 1 + m, A[i]) - B;
    26             if(B[x] >= A[i]) x--;
    27             if(x < 0) x = 0;
    28             if(x > m) x = m;
    29             b = x * 2 + (m - x) * 3;
    30             if(i == n + 1) {
    31                 a = 2 * n, b = 2 * m;
    32             }
    33             if(a - b == s && a > res1) {
    34                 res1 = a, res2 = b;
    35             }
    36             if(a - b > s) {
    37                 s = a - b;
    38                 res1 = a, res2 = b;
    39             }
    40         }
    41 
    42         if(res1 < 0) res1 = 0;
    43         if(res2 < 0) res2 = 0;
    44         cout << res1 << ':' << res2 << endl;
    45     }
    46     return 0;
    47 }
    View Code
  • 相关阅读:
    时间工时累加
    python读取mnist
    开始学习haskell
    pip升级所有packages
    ImportError: numpy.core.multiarray failed to import
    NumPy for MATLAB users
    Spyder
    初学ObjectiveC
    Matlab闭包
    ObjeciveC 内存管理
  • 原文地址:https://www.cnblogs.com/usedrosee/p/4150237.html
Copyright © 2011-2022 走看看