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\n",L,R);
48     return 0;
49 }

时间: 2024-07-31 21:38:55

codeforces 493 C Vasya and Basketball的相关文章

codeforces 493 D Vasya and Chess【 博弈 】

题意:给出n*n的棋盘,白方在(1,1),黑方在(1,n)处,每一步可以上下左右对角线走,哪个先抓到另一个,则它获胜 可以画一下,发现n是奇数的时候,白方先走,无论它怎么走,黑方和它走对称的,黑方都一定能赢 n是偶数的时候,将白方走到(1,2)就变成奇数的情况,白方必胜 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<st

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 493 ABCD

A. Vasya and Football A. Vasya and Football time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Vasya has started watching football games. He has learned that for some fouls the players receiv

Vasya and Basketball CodeForces - 493C

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

codeforces 493C Vasya and Basketball(二分)

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

codeforces 1041 E.Vasya and Good Sequences(暴力?)

E. Vasya and Good Sequences time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya has a sequence $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. Vasya may pefrom the fol

Codeforces 1053 B - Vasya and Good Sequences

B - Vasya and Good Sequences 思路: 满足异或值为0的区间,必须满足一下条件: 1.区间中二进制1的个数和为偶数个; 2.区间二进制1的个数最大值的两倍不超过区间和. 如果区间长度大于128,第二个条件肯定满足,所以我们只要暴力区间长度小于128的就可以了 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) #include<bits/stdc++.h> using

Codeforces 1082 A. Vasya and Book-题意 (Educational Codeforces Round 55 (Rated for Div. 2))

A. Vasya and Book time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya is reading a e-book. The file of the book consists of nn pages, numbered from 11 to nn. The screen is currently disp