Codeforces #281 (Div. 2)C Vasya and Basketball(二分)
2014-12-04 16:44
267 查看
题目链接:【戳】
题意相对比较简单,两个人比赛篮球投篮,与正常的篮球比赛不同的是,三分线与篮筐的距离d是不确定的。输入第一个人投了n个球,n个球每个球投的时候他与篮筐的距离;然后输入第二个人头了m个球,m个球每个球投的时候他与篮筐的距离。
然后让你选择一个d,使得它对于第一个人最为有利,所谓有利即使得“第一个人的分数-第二个人的分数”最大,将比分输出。当有多个相同的最大差值的情况时,输出第一个人分数最大的那组。
只要对于枚举的一个距离x,每个人得到的分数则可以表示成:(比x近的个数)*2 + (比x远的个数)*3
所以只需要枚举(m+n+1)种情况,然后分别二分找到枚举的距离在n个球和m个球中的排第几,即可算出两者分差。
代码:
题意相对比较简单,两个人比赛篮球投篮,与正常的篮球比赛不同的是,三分线与篮筐的距离d是不确定的。输入第一个人投了n个球,n个球每个球投的时候他与篮筐的距离;然后输入第二个人头了m个球,m个球每个球投的时候他与篮筐的距离。
然后让你选择一个d,使得它对于第一个人最为有利,所谓有利即使得“第一个人的分数-第二个人的分数”最大,将比分输出。当有多个相同的最大差值的情况时,输出第一个人分数最大的那组。
只要对于枚举的一个距离x,每个人得到的分数则可以表示成:(比x近的个数)*2 + (比x远的个数)*3
所以只需要枚举(m+n+1)种情况,然后分别二分找到枚举的距离在n个球和m个球中的排第几,即可算出两者分差。
代码:
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath> #include <algorithm> #include <map> using namespace std; typedef long long LL; LL a[200010], b[200010], c[400010]; int t, n, m; int main() { scanf("%d", &n); int num = 1; for(int i = 1; i <= n; i++) { scanf("%I64d", &a[i]); c[num++] = a[i]; } sort(a+1, a+n+1); scanf("%d", &m); for(int i = 1; i <= m; i++) { scanf("%I64d", &b[i]); c[num++] = b[i]; } sort(b+1, b+m+1); sort(c+1, c+num); LL ans = (LL)(-1e10); LL x, y; if(ans < n * 2 - m * 2) { x = (LL)n * 2; y = (LL)m * 2; ans = x - y; } for(int i = num - 1; i >= 0; i--) { //cout<<c[i]<<endl; 小于等于个数 int tmp1 = upper_bound(a+1, a+n+1, c[i]) - a - 1; int tmp2 = upper_bound(b+1, b+m+1, c[i]) - b - 1; //cout<<tmp1 << " "<< tmp2<<endl; if(ans <= (LL)tmp1*2+(LL)(n-tmp1)*3 - (LL)tmp2*2-(LL)(m-tmp2)*3) { x = (LL)tmp1*2+(LL)(n-tmp1)*3; y = (LL)tmp2*2+(LL)(m-tmp2)*3; ans = x - y; } } cout<<x<<":"<<y<<endl; return 0; }
相关文章推荐
- Codeforces #281 (Div. 2)C Vasya and Basketball(二分)
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball 枚举+二分
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分
- Codeforces Round #354 (Div. 2) C - Vasya and String(二分)
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball&D. Vasya and Chess
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball
- Codeforces Round #354 (Div. 2) C Vasya and String(尺取法二分)
- Codeforces Round 281 div2 C Vasya and Basketball
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball 暴力水题
- Vasya and Basketball codeforces 493c 二分二分
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball
- Codeforces Round #354 (Div. 2) C. Vasya and String 二分
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball 排序
- CF_493 C- Vasya and Basketball(二分)
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 水
- Codeforces Round #354 (Div. 2)C. Vasya and String(尺取法)
- Codeforces #275 (Div. 2) B - Friends and Presents(二分大法好)
- [思路题] Codeforces 354C #206 (Div. 1) C. Vasya and Beautiful Arrays
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分