“蔚来杯“2022牛客暑期多校训练营2

本文讨论了一款游戏中由于资源兑换规则错误导致的无限资源问题,通过引入参数w修复,并介绍了如何利用二分查找和Bellman-Ford算法避免无限资源的产生。此外,还涉及到了DP解决括号序列问题以及寻找排列最小价值的方法。同时,文章提到了电梯调度问题的优化策略和等差序列最小修改成本的线性回归解法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

D Link with Game Glitch

Link is developing a game. In this game, players can craft things using various types of resources, and things crafted can also be used to craft other things.

Formally speaking, there are nn types of items, numbered from 11 to nn, and mm recipes in the game. In the ii-th recipe, players can use ka_ik∗ai​ items of the b_ibi​-th type to craft kc_ik∗ci​ items of the d_idi​-th type, where kk can be any positive real number.

One day, he finds that one player owns more than 18,446,744,073,709,551,615 identical items, which causes a server crash. This is obviously impossible without using glitches.

Link soon finds out that there is something wrong with the crafting recipe. Players may get infinite resources by crafting some special things over and over again!

Link doesn’t want to adjust the recipes one by one, so he simply added an argument ww. Now players can use ka_ik∗ai​ items of the b_ibi​-th type to craft wk*c_iw∗k∗ci​ items of the d_idi​-th type.

Link wonders: What’s the maximum ww that he can set so that no player can get infinite items by crafting things over and over again?

在游戏中有n中物品和m种兑换规则,你可以用 k ∗ a i 个 b i 去兑换 k ∗ c i 个 d i k*a_i个b_i去兑换k*c_i个d_i kaibi去兑换kcidi,k不一定是整数
但是这个规则出现了问题,即图中出现了边权积大于1的环
这里我们可以用二分求得答案
由于边权积过大,long long肯定是不够的,我们可以把边权转化为对数,再用bellman_ford算法(有负权边)求最短路,如果出现大于0的距离,即 l o g x > 0 logx>0 logx>0那么则有x大于1,说明二分的该答案有问题,继续向下二分得到结果
tags:二分 最短路(Bellman_Ford)

AC代码

/****************
 *@description:for the Escape Project
 *@author: Nebula_xuan
 * @Date: 2022-07-26 11:22:44
 *************************************************************************/

#include <bits/stdc++.h>

using namespace std;
const int N = 1e3 + 10, M = 2e3 + 10;
const double eps = 1e-9;
long long n, m, a[M], b[M], c[M], d[M];
double dist[N], w[M];
int Bellman_Ford()
{
   
   
    for (int i = 1; i <= n; i++)
        dist[i] = 0.0;
    bool flag = false;
    for (int i = 1; i < n; i++)
    {
   
   
        flag = false;
        for (int j = 1; j <= m; j++)
        {
   
   
            if (dist[b[j]] + w[j] < dist[d[j]])
            {
   
   
                flag = true;
                dist[d[j]] = dist[b[j]] + w[j];
            }
        }
        if (!flag)
            return false;
    }
    return true;
}
int main()
{
   
   
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    double l = 0.0, r = 1.0;
    while (r - l > eps)
    {
   
   
        double mid = (l + r) / 2.0;
        for (int i = 1; i <= m; i++)
            w[i] = -log(1.0 * c[i] * mid / a[i]);
        if (!Bellman_Ford())
            l = mid;
        else
            r = mid;
    }
  	printf("%.10lf\n",l);
}

K Link with Bracket Sequence I

Link has a bracket sequence aa of length nn, which is a subsequence of a valid bracket sequence bb of length mm.

Link doesn’t remember bb, so he wonders the number of possible sequences bb.

A bracket sequence is valid if it satisfies any of the following conditions:

  • Its length is 00.

  • It can be represented as (A)(A), where AA is a valid bracket sequences.

  • It can be represented as ABAB, where AA and BB are both valid bracket sequence.

A sequence aa is a subsequence of a sequence bb if aa can be obtained from bb by deletion of several (possibly, zero or all) elements.

给你一个长度为n的括号序列,问你长度为m的原序列(且合法)的情况有多少种
这里我们用DP进行考虑,有 f [ i ] [ j ] [ k ] f[i][j][k] f[i][j][k],其中i表示原序列的长度
,j表示匹配的长度,k表示左括号比右括号多k的时的方案数
当我们选择添加一个左括号时,可以随意添加
但是如果我们添加的是一个右括号,当且仅当左括号数量大于右括号数量的时候匹配才成立

tags:DP

AC代码

/****************

 *@description:for the Escape Project

 *@author: Nebula_xuan

 * @Date: 2022-07-26 10:48:24

 *************************************************************************/

  

#include <bits/stdc++.h>

  

using namespace std;

  

const int N = 2e2 + 10;

long long  f[N][N][N];

const int MOD = 1e9 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

能工智人小辰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值