C. Vasya and Basketball

2024-01-21 10:58
文章标签 vasya basketball

本文主要是介绍C. Vasya and Basketball,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

·真的是发现每题都有坑。。。

这题主要目的是求一个3分的分界线。题意就不多说了,主要说下自己的思路:

思路:  

  定义结构体,标识每个分数属于哪个队伍,然后将两个队伍的得分放在同一个数组中,从小到大进行排序。

  之后从后向前。(即从大分数向小分数)

  按照分数计算出Max{num1-num2};(num1为大于等于当前分数的队伍一的投球个数;num2为大于等于当前分数的队伍二的投球个数。)

  算出临界点的球数差值对应的分数就为3分与2分得分界线。

  之后进行计算得分输出即可。

·注意一个坑点: If there are several such scores, find the one in which number a is maximum.

   这就需要将分界线订的越小越好,这样每队的得分才能更高,也就是令a越大。

 

AC Code:

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <string.h>
 6 #include <math.h>
 7 #include <queue>
 8 #include <stack>
 9 #include <stdlib.h>
10 #include <map>
11 using namespace std;
12 #define LL long long
13 #define sf(a) scanf("%d",&(a));
14 #define N 500010
15 
16 typedef struct LNode{
17     int flag;
18     int x;
19 }LNode;
20 LNode f[N];
21 int cmd(LNode x,LNode y){
22     return x.x < y.x; //从小到大排序
23 }
24 int last=0;int flag=0;
25 int main()
26 {
27     int n,m;
28     scanf("%d",&n);
29     for(int i=0;i<n;i++){
30         scanf("%d",&f[i].x);
31         f[i].flag=1;
32     }
33     scanf("%d",&m);
34     for(int i=n;i<n+m;i++){
35         scanf("%d",&f[i].x);
36         f[i].flag = 2;
37     }
38     sort(f,f+n+m,cmd); //从小到大排序
39 //    for(int i=0;i<n+m;i++){
40 //        printf("%d %d\n",f[i].flag,f[i].x);
41 //    }
42     int num1=0,num2=0;
43     int wei=f[n+m-1].x;
44     int maxc=-(1<<30);
45     for(int i=(n+m-1);i>=0;i--){
46         while(1){
47             if(f[i].flag==1) num1++;
48             else num2++;
49 
50             if(i>0 && (f[i-1].x == f[i].x)){
51                 i--;continue;
52             }
53             else break;
54         }
55         //printf("num : %d %d\n",num1,num2);
56         int t = num1-num2;
57         if(t >= maxc){     //-------------一开始这里WA了一发, 没考虑到题目中说的,当相差分数相同时,选择a最大的情况,这里需要另wei最小!
58 
59             if(flag==0){
60                 last = t;
61                 flag=1;
62                 maxc = t;
63                 wei = f[i].x; //表示相差最大的时候,其3分线为多少。
64             }else{
65 
66                     maxc = t;
67                     wei = f[i].x; //表示相差最大的时候,其3分线为多少。
68                     last = t;
69 
70             }
71         }
72     }
73     //printf("num: %d %d\n",num1,num2);
74     //以 wei-1 为2分线,大于其的为3分。
75     //printf("分界线分数:%d\n",wei-1);  //这里值可以为0!!!
76 
77     num1=num2=0;
78     if(maxc < 0) wei =f[n+m-1].x+1;  //这里判断一定要加 , 不然也会WA
79     for(int i=0;i<n+m;i++){
80         if(f[i].flag==1) {
81             if(f[i].x >=wei) num1+=3;
82             else num1+=2;
83         }
84         else{
85             if(f[i].x >=wei) num2+=3;
86             else num2+=2;
87         }
88     }
89     printf("%d:%d\n",num1,num2);
90 
91     return 0;
92 }

 

 其实这道题目的测试数据很好想,正规比赛应该自己多测几组的,以后多注意。

这篇关于C. Vasya and Basketball的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/629295

相关文章

Ural 1353 Milliard Vasya's Function(DP)

题目地址:Ural 1353 定义dp[i][j],表示当前位数为i位时,各位数和为j的个数。 对于第i位数来说,总可以看成在前i-1位后面加上一个0~9,所以状态转移方程就很容易出来了: dp[i][j]=dp[i][j]+dp[i][j-1]+dp[i][j-2]+.......+dp[i][j-9]; 最后统计即可。 代码如下: #include <iostream>#in

Codeforces Contest 1073 problem C Vasya and Robot —— 尺取

Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell (0,0). Robot can perform the following four kinds of operations: U — move from (x,y) to (x,y+1); D — move

CODEFORCES --- 581A. Vasya the Hipster

581A. Vasya the Hipster 有一天,时髦精瓦夏决定数一数他有多少袜子。原来,他有 a 双红袜子和 b 双蓝袜子。按照最新的时尚,潮人应该穿不同颜色的袜子:左脚一只红袜子,右脚一只蓝袜子。每天早上,瓦夏都会穿上新袜子,然后在睡觉前扔掉,因为他不想洗袜子。 瓦夏想知道,他最多有多少天可以穿得很时髦,穿不同的袜子,之后,他又有多少天可以穿同样的袜子,直到袜子用完,或者用现有的袜子

cf Educational Codeforces Round 26 E. Vasya's Function

原题: E. Vasya’s Function time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Vasya is studying number theory. He has denoted a function f(a, b

cf Educational Codeforces Round 53 C. Vasya and Robot

原题: C. Vasya and Robot time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Vasya has got a robot which is situated on an infinite Cartesian plane,

Div. 2 ,C. Vasya and Robot

这个题目第一眼看并不是一个二分,仔细思考一下,要枚举长度,然后又要枚举起点,这里已经是O(n^2)的复杂度了,还要判断是否满足条件,如果预处理了,是能在O(1)的复杂度解决的。所以枚举长度这边可以用一个二分,这样复杂度就是O(nlogn)了,可以解决这个题目。 如何在O(n)的复杂度判断这个长度满不满足要求呢? 枚举起点就要O(n)了,接下来就是O(1)判断O不OK;预处理到第i个字母时往右往

Vasya and Petya's Game CodeForces - 577C

http://codeforces.com/problemset/problem/577/C 问序列中最少含几个数 使得1-n的每一个数都能用序列中的几个数相乘得到 把每个数都素因子分解为(2^p1)*(3^p2)*(5^p3)...这种形式 把2^1...2^p1等都扔数组里去个重就好   #include <bits/stdc++.h>using namespace std;con

Educational Codeforces Round 50 (Rated for Div. 2)D. Vasya and Arrays(前缀和)

题目链接:http://codeforces.com/contest/1036/problem/D 题意:给你两个序列,问是否可以转换(相邻相加)成两个相同的字符串,如果不可以输出 -1,如果可以问最大长度是多少。 思路:前缀和标记a数组,b数组统计贡献。 AC代码: #include <bits/stdc++.h>using namespace std;#define ll long

Basketball Exercise CodeForces - 1195C(动态规划dp)

Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2⋅n students have come to Demid’s exercise session, and he lined up them into two rows o

XKC's basketball team(2019徐州站网络赛E线段树)

题目链接:题目链接嘤嘤嘤 一开始以为是主席树,想明白了之后线段树就可以。从后往前遍历,线段树二分查找离这个数最远的数字。返回那个数的下标。这个数查找完了就把这个数插入到线段树里。 代码如下: #include<bits/stdc++.h>#define ll long longusing namespace std;const int maxx=5e5+100;struct node{in