UVALive 7147 World Cup(2014 Regionals 2014 :: Asia - ShangHai)

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=94610#problem/J

 

problemIn normal football games, the winner team gets 3 points, loser team gets 0 point, and if there is a drawgame, both of the teams get 1 point.

In normal football games, the winner team gets 3 points, loser team gets 0 point, and if there is a draw

game, both of the teams get 1 point.
In World Cup 1994, Group D there is an interest thing happened. There are 4 teams in that group,
Argentina, Nigeria, Bulgaria and Greece. Greece lost all the 3 matehes and scored 0. Argentina defeated
Nigeria, Nigeria defeated Bulgaria and Bulgaria defeat Argentina. Since there are only 2 teams could
advance to the next stage, one of the 3 teams will be eliminated. It’s really a surprise that a team
scored 6 will be eliminated in a 4 advance 2 group competition. That is really interesting and we’d like
to dig it deeper.
In this problem, there are N teams in a group. Within a group, any two teams will play each other
exactly once, so each team will have N − 1 matches in total.
In a match, the winner team will get A points and the loser team gets C points. If the match ends
with a draw, each of the teams gets B points. When all matches finished, the teams will be ranked by
their score (in case of multiple teams get the same score, they will be ordered randomly), and the top
M teams from the group can advance to the next stage.
Our questions are: What is the maximum possible score that a team can earn and still not advance?
(Note that there may be other teams in the same group that also earn that same score and do advance.)
Similarly, what is the minimum possible score that a team can earn and still advance?
Input
The first line of the input gives the number of test cases, T. T cases follow. Each case has two lines.
The first line contains two numbers, N and M. The second line contains three numbers, A, B, and C.
Output
For each test case, output one line containing ‘Case #x: y z’, where x is the test case number (starting
from 1) and y is maximum score that a team may be eliminated. z is the minimum score that a team
may advance to the next stage.
Limits:
1 ≤ T ≤ 100,
1 ≤ M < N ≤ 109
,
0 ≤ A, B, C ≤ 109
,
Sample Input:
3
4 2
3 1 0
4 2
3 2 0
2 1
2 3 1

Sample Output:
Case #1: 6 2
Case #2: 7 3
Case #3: 3 2

题意:有n个人参加比赛,只有m个人才能晋级,现在知道赢的分数,平局的分数,输的分数,问一个选手不能晋级时可能得到的最多分数,和可以晋级时可能得到的最少的分数。

 

不能晋级得到的最高分数:尽可能的让第m+1个人和前m个人达到分数相同的状态(共有m场比赛,可以让所有人平局,也可以赢一次输一次,注意奇数时的特判),并且赢了后面所有的人(或者和后面所有人平局);

能晋级得到的最低分数:让第m个人输给前面所有的人(或者和前面所有人平局),尽可能的让他与后面的人得到相同的分数(共有n-m场比赛,可以让所有人平局,也可以赢一次输一次,注意奇数时的特判)。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<queue>
#include<algorithm>
using namespace std;

const int N=1e5+10;
const int M=50000;
const int INF=0x3f3f3f3f;

int main ()
{
    int T, k = 0;
    long long Min, Max, m, n, a, b, c, x1, y1, x2, y2; ///x计算的是最高不能晋级的,y计算的是最低可以晋级的

    scanf("%d", &T);

    while (T--)
    {
        k++;

        scanf("%lld%lld", &n, &m);
        scanf("%lld%lld%lld", &a, &b, &c);

        if (a < c) swap(a, c); ///赢的人得到的分数可能比输的人得到的分数要少

        x1 = (n-m-1)*max(a, b); ///计算第m+1个人与后面所有人比赛得到的分数
        x2 = m/2 * 2*b; ///计算第m+1个人与前面所有人平局的分数,由于m可能是奇数,当它为奇数时,此时第m场比赛得到的分数还没有算
        if (m % 2 == 0)
        {
            x2 = max(x2, m/2*(a+c)); ///为偶数,直接比较赢一次输一次和平局的大小
            Max = x1 + x2;
        }
        else
        {
            x2 = max(x2, m/2*(a+c)); ///为奇数,先比较前m-1场比赛中赢一次输一次和平局的大小
            Max = x1 + x2 + max(b, c); ///第m场比赛,需要比较输和平局的大小,再赢就可以晋级了
        }

        y1 = (m-1)*min(c, b);
        y2 = (n-m)/2 * 2*b;
        if ((n-m) % 2 == 0)
        {
            y2 = min(y2, (n-m)/2*(a+c));
            Min = y1 + y2;
        }
        else
        {
            y2 = min(y2, (n-m)/2*(a+c) );
            Min = y1 + y2+min(a, b); ///第n-m场比赛,需要比较赢和平局的大小,再输就不能晋级了
        }

        printf("Case #%d: %lld %lld\n", k, Max, Min);
    }

    return 0;
}

转载于:https://www.cnblogs.com/syhandll/p/4906539.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]:这段引用是一段C++代码,用于处理一个01序列的查询。代码中使用了前缀和和后缀和的思想,通过计算每个位置之前1的个数和之后1的个数,来处理查询区间内的操作。具体的实现细节可以参考代码注释。\[1\] 引用\[2\]:在处理多组询问时,为了不改变非连续1的计数,代码将区间分成两段处理。左半段都是1的情况单独处理,后半段第一个位置为0,可以通过前缀和相减来计算。这样可以保证在处理查询时不会影响到非连续1的计数。\[2\] 引用\[3\]:这段引用是对一个二进制循环序列的定义和问题描述。一个好的二进制循环序列是指通过一系列操作可以使其变为空序列。而一个二进制循环序列的美丽度被定义为使其变为好序列所需的最小修改次数。每次修改可以翻转序列中的任意一个元素,即0变为1,1变为0。给定一个长度为n的二进制字符串a和q个查询,每个查询给出两个整数li和ri,需要回答f(aliria\[li..ri\]),其中我们将子字符串aliria\[li..ri\]视为一个循环序列。\[3\] 问题: 请问这段代码的作用是什么? 回答: 这段代码的作用是处理一个01序列的查询。通过计算每个位置之前1的个数和之后1的个数,来处理查询区间内的操作。在处理多组询问时,为了不改变非连续1的计数,代码将区间分成两段处理,保证在处理查询时不会影响到非连续1的计数。最终输出每个查询区间的结果。\[1\]\[2\] #### 引用[.reference_title] - *1* *2* [ICPC22网络赛(1) - A 01 Sequence(前缀和,思维)](https://blog.csdn.net/Mr_dimple/article/details/126983251)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [The 2022 ICPC Asia Regionals Online Contest - A 01 Sequence](https://blog.csdn.net/qq_35339563/article/details/126959132)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值