广东省第十八届大学生程序设计竞赛(A,D,G,J,L)

A - An Easy Problem

Measuring the area of a certain shape is an important part of certain geometric problems. For a point A(x,y) on the plane, we define the F(x,y) as |x|*|y|,which means the area of the rectangle with the vertex(x, 0),(y, 0),(0, 0),(x, y). You are given n∗ m vertex with integral coordinates in the form of ( i, j ),and 1 ≤ i ≤ n, 1 ≤ j ≤ m. You need to find the K-th biggest value of F(i,j),when 1 ≤ i ≤ n, 1 ≤ j ≤ m. It’s guranteed that K ≤ n ∗ m

题目大意:
给你三个数n,m,k
然后会根据n,m生成数列
1×1,1×2,······,1×m
2×1,2×2,······,2×m
···
n×1,n×2,······,n×m
问你将这些数字中第k大的数字是多少

我们可以建一个最大堆(优先队列)

for(i : = 1 i <= N;i++)

将i *M 和 i 本身作为一个pair放入优先队列中(可以有效减少堆中元素,因为数据量较大,全部情况放入估计超时了)然后每次将最大pair出队,通过first - second 引入最大N * (M-1)的情况,再做出比较,如此往复K - 1次,最后堆顶元素就是我们需要的答案

#include<bits/stdc++.h>

using namespace std;
#define int long long
priority_queue < pair<int, int>>ans;
int N, M, K, A, B;
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N >> M >> K;
    for (int i = 1; i <= N; i++)
        ans.emplace(i * M, i);
    while (--K)
    {
        A = ans.top().first;
        B = ans.top().second;
        ans.pop();
        ans.emplace(A - B, B);
    }
    cout << ans.top().first << endl;
    return 0;
}

D - Double

题目

最近,Jvruo 迷上了一款格斗游戏。在这个游戏中,n 个角色从左到右站在竞技场上,第i个角色的战斗力是 ai。对于每个操作,Jvruo 将在竞技场上选择两个相邻的字符 x 和 y 进行决斗。如果 ax > ay,那么 x 赢了,如果 ax < ay,那么 y 赢了。如果 ax = ay,那么 x 和 y 都有50% 的概率获胜。获胜的角色将留在竞技场,战斗力翻倍; 失败的角色将离开竞技场。现在 Jvruo 将执行 n-1操作,在 n-1操作之后,环中将只剩下一个字符。显然,Jvruo 有(n-1) !操作模式。在所有这些操作模式中,哪些角色有可能留到最后并成为最终的赢家。

简单来说就是给我们一串数字,通过和左右俩边进行比大小,赢了可以翻倍,直到它能坚持到打败所有其他数字就将其记录到可能成为最后赢家的行列中,问有几个这样的数字,并输出他们的下标

首先:在我们输入样例的时候就可以定义一个变量K记录所有角色的最大战斗力的值.

对于是否能坚持到最后一个,其实只要判断他在N次对比中,能否成长为最大战斗力的值,如果可以就不需要比较了,最大值都有可能战胜其他数字都能战胜,因此我们判断这个数字是可能坚持到最后的,记为win = true;将其放入ans中.

反之:

如果这个数战斗力成长未到最大值:并且对于左右俩边的对手都不能比他们大,显然他是无法坚持到最后的,记为win = false 直接跳过即可

#include <bits/stdc++.h>
using namespace std;
#define int long long 
int N, M, K;
const int maxn = 500005;
vector<int>nums(maxn);
vector<int>ans;
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> nums[i];
        K = max(K, nums[i]);
    }
    for (int i = 0; i < nums.size(); i++)
    {
        int L = i - 1, R = i + 1, sum = nums[i];
        bool win = false;
        while (1)
        {
            if (sum >= K)
            {
                win = true;
                break;
            }
            if (L >= 0 && nums[L] < sum)
            {
                sum *= 2;
                L--;
            }
            else if (R < N && nums[R] < sum)
            {
                sum *= 2;
                R++;
            }
            else
                break;
        }
        if (win)ans.emplace_back(i + 1);
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
    {
        if (i)cout << " " << ans[i];
        else cout << ans[i];
    }
        return 0;
}
GGood Game, GG

爱丽丝和鲍勃在玩游戏。最初有 n 个正数,第 i 个数是 ai。在一个回合中,爱丽丝可以选择一个奇数并把它除成两个正数,或者删除一个等于1的数。Bob 可以选择一个偶数并将它分成两个正数。两个玩家轮流移动,爱丽丝先移动。轮到一个人的时候,如果他或她不能移动,他或她就输掉了比赛。如果两个玩家移动最佳,请找出谁是赢家。您需要回答 T 查询。

题目大意

爱丽丝可以操作奇数使得它分成俩个整数例如:7 = 2 + 5;或者也可以删除一个1

鲍勃可以将偶数分成俩整数,爱丽丝先操作,直到一方无法进行自己的操作即为失败

首先:都做最优操作,那么鲍勃一定将偶数拆成俩个偶数

但是:爱丽丝最优也只能将一个奇数分成一奇一偶.

不过,有一个特殊的偶数:即是2,对于2,鲍勃的最优解是不去动2这个数字,如果将2拆分只能是1 1,

这样爱丽丝就多了俩个操作空间,因此2不算在鲍勃的操作集中,那么,爱丽丝的操作一定是最优于自己的,即将一个奇数分成2+奇数.对于一个奇数可以执行(奇数本身 + 1)/2次操作(爱丽丝可以删1).

而鲍勃由于不能分2,对于一个偶数可以进行(偶数本身) / 2 - 1次操作,我们记录俩人可从操作次数,若奇 > 偶即可判断爱丽丝获胜,反之鲍勃获胜

#include<bits/stdc++.h>
using namespace std;
#define int long long
int ji, ou, N, num, M;
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N;
    while (N--)
    {
        cin >> M;
        ji = ou = 0;
        while (M--)
        {
            cin >> num;
            if (num & 1)
                ji += (num + 1) / 2;
            else
                ou += num / 2 - 1;
        }
        if (ji > ou)cout << "Alice" << endl;
        else cout << "Bob" << endl;
    }
    return 0;
}

L - League of Legends

QAZ likes to play League of Legends and watch league matches as well.

He thinks the double-elimination system of this year’s league matches is not fair, so he invented a prodouble-elimination system.

Specifically, in his system:

• There are three teams competing with each other.

• Firstly, two teams are selected with equal probability and compete.

• In each round, the losing team temporarily leaves, and the winning team continues to play against the other of the three teams that did not participate in this round.

• When a team loses two round in total, the elimination competition ends.

• For the sake of simplicity, any two teams have a 50% chance of winning against each other.

• Now please find out the expected number of rounds in this elimination competition.

题目:

他认为今年联赛的双淘汰制不公平,所以他发明了一种双淘汰英雄联盟。具体来说,在他的系统中: 有三个团队在相互竞争。•首先,以同样的概率选出两支队伍进行竞争。在每一轮中,输的一方暂时离开,获胜的一方继续与没有参加本轮比赛的三支队伍中的另一支队伍进行比赛。•当一支球队总共输掉两轮时,淘汰赛结束。•为了简单起见,任何两支球队都有50% 的机会相互制胜。•现在请查询预计的淘汰赛次数。

这是一道高中概率求期望的题目,计算出答案直接输出即可

#include<bits/stdc++.h>
using namespace std;
int main()
{
    cout << "3.5" <<endl;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值