Codeforces ZeptoLab Code Rush 2015

本文解析了 Codeforces ZeptoLab CodeRush 2015 的四道题目,包括 King of Thieves 中的平台跳跃算法、Om Nom and Dark Park 中的满二叉树路径平衡问题、Om Nom and Candies 中的最大幸福值选择策略以及 Om Nom and Necklace 中的序列规律判断。

Codeforces ZeptoLab Code Rush 2015


比赛链接:http://codeforces.com/contest/526/


A. King of Thieves
time limit per test:1 second
memory limit per test:256 megabytes

In this problem you will meet the simplified model of game King of Thieves.

In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.

An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.

A dungeon consists of n segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as'*' and pits are represented as '.'.

One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform numberi1, he can make a sequence of jumps through the platformsi1 < i2 < ... < ik, ifi2 - i1 = i3 - i2 = ... = ik - ik - 1. Of course, all segments i1, i2, ...ik should be exactly the platforms, not pits.

Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequencei1, i2, ..., i5, consisting offive platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of segments on the level.

Next line contains the scheme of the level represented as a string ofn characters '*' and '.'.

Output

If the level is good, print the word"yes" (without the quotes), otherwise print the word"no" (without the quotes).

Sample test(s)
Input
16
.**.*..*.***.**.
Output
yes
Input
11
.*.*...*.*.
Output
no
Note

In the first sample test you may perform a sequence of jumps through platforms2, 5, 8, 11, 14.


题目大意:给个字符串,问能不能找到连续5个下标成等差数列的位置上字符都为' * '的情况


题目分析:数字小,暴力枚举公差,然后模拟


#include <cstdio>
#include <cstring>
char s[105];
int a[105];

int main()
{
    int len;
    bool flag = false;
    scanf("%d %s", &len, s);
    int d = 1;
    while(d <= len / 4)
    {
        for(int i = 0; i < len; i++)
        {
            if(s[i] == '*' && s[i + d] == '*' && s[i + 2 * d] == '*' && s[i + 3 * d] == '*' && s[i + 4 * d] == '*')
            {
                flag = true;
                break;
            }
        }
        d ++;
        if(flag)
            break;
    }
    if(flag)
        printf("yes\n");
    else
        printf("no\n");
}   


B. Om Nom and Dark Park
time limit per test:1 second
memory limit per test:256 megabytes

Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who likes visiting friends living at the other side of the park. However the dark old parks can scare even somebody as fearless as Om Nom, so he asks you to help him.

The park consists of 2n + 1 - 1 squares connected by roads so that the scheme of the park is a full binary tree of depthn. More formally, the entrance to the park is located at the square1. The exits out of the park are located at squares2n, 2n + 1, ..., 2n + 1 - 1 and these exits lead straight to the Om Nom friends' houses. From each squarei (2 ≤ i < 2n + 1) there is a road to the square. Thus, it is possible to go from the park entrance to each of the exits by walking along exactlyn roads.

To light the path roads in the evening, the park keeper installed street lights along each road. The road that leads from square i to square has ai lights.

Om Nom loves counting lights on the way to his friend. Om Nom is afraid of spiders who live in the park, so he doesn't like to walk along roads that are not enough lit. What he wants is that the way to any of his friends should have in total the same number of lights. That will make him feel safe.

He asked you to help him install additional lights. Determine what minimum number of lights it is needed to additionally place on the park roads so that a path from the entrance to any exit of the park contains the same number of street lights. You may add an arbitrary number of street lights to each of the roads.

Input

The first line contains integer n (1 ≤ n ≤ 10) — the number of roads on the path from the entrance to any exit.

The next line contains 2n + 1 - 2 numbersa2, a3, ...a2n + 1 - 1 — the initial numbers of street lights on each road of the park. Hereai is the number of street lights on the road between squaresi and . All numbersai are positive integers, not exceeding100.

Output

Print the minimum number of street lights that we should add to the roads of the park to make Om Nom feel safe.

Sample test(s)
Input
2
1 2 3 4 5 6
Output
5
Note

Picture for the sample test. Green color denotes the additional street lights.




题目大意:一颗满二叉树,每条路上有一个权值表示灯的个数,现在要从根到所有叶子的路径上灯个数总和相同,问至少需要添加多少灯


题目分析:若要相等,显然兄弟到父亲路径上的灯数要一样,因此直接从叶子向上模拟即可,将灯数不断累加给父亲一直到根,每次兄弟到父亲路径上的差值的和就是最少需要补充的灯数


#include <cstdio>
#include <algorithm>
using namespace std;
int n, a[5000];

int main()
{
    int ans = 0;
    scanf("%d", &n);
    for(int i = 2; i <= (1 << (n + 1)) - 1; i++)
        scanf("%d", &a[i]);
    for(int i = (1 << (n + 1)) - 1; i >= 2; i -= 2)
    {
        ans += abs(a[i] - a[i - 1]);
        a[i / 2] += max(a[i], a[i - 1]);
    }
    printf("%d\n", ans);
}




C. Om Nom and Candies
time limit per test:1 second
memory limit per test:256 megabytes

A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place?

One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighsWr grams and each blue candy weighsWb grams. Eating a single red candy gives Om NomHr joy units and eating a single blue candy gives Om NomHb joy units.

Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more thanC grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.

Input

The single line contains five integers C, Hr, Hb, Wr, Wb (1 ≤ C, Hr, Hb, Wr, Wb ≤ 109).

Output

Print a single integer — the maximum number of joy units that Om Nom can get.

Sample test(s)
Input
10 3 5 2 3
Output
16
Note

In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.


题目大意:红糖有wr克,每克能得到hr的幸福值,蓝糖有wb克,每克能得到hb的幸福值,现在问最多吃c克能得到的最大幸福值


题目分析:这样的数据量显然不能用背包做,采用部分贪心策略,及另lcm为wr和wb的最小公倍数,如果c % lcm == 0且c / lcm >= 2,则对于容量为w1 = c / lcm - 1(这里减1是因为保证结果尽可能的大,如果直接取c/lcm的话不能除尽的部分可能会有很多空余位置)的部分我们可以直接贪心,结果记为sum,sum =w1 * max(lcm / wb * hb,lcm / wr * hr),剩下的部分直接枚举,枚举的时候取min(c / wr,c / wb)作为上界,这样可以防止超时。不妨假设wr比wb大,若wr数值很大,则枚举的时候c / wr就很小,若wr很小,则c = c % lcm后c就很小,则此时c / wr还是很小,由此可得本题部分贪心+部分暴力的方法是可行的


#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std; 

ll Gcd(ll a, ll b)
{
    return b ? Gcd(b, a % b) : a;  
}

ll Lcm(ll a, ll b)
{
    return a * b / Gcd(a, b);
}
int main()
{
    ll c, h1, h2, w1, w2, ans = 0; 
    //scanf("%lld %lld %lld %lld %lld", &c, &w1, &h1, &w2, &h2);
    scanf("%I64d %I64d %I64d %I64d %I64d", &c, &h1, &h2, &w1, &w2);
    ll lcm = Lcm(w1, w2);
    ll tmp = c / lcm;
    c = c % lcm;
    if(tmp)
    { 
        tmp --; 
        c += lcm; 
    } 
    ll sum = tmp * (max(lcm / w1 * h1, lcm / w2 * h2));
    if(w1 < w2)
    {
        swap(w1, w2);
        swap(h1, h2);
    }
    for(int i = 0; i <= c / w1; i++)
        ans = max(ans, i * h1 + (c - i * w1) / w2 * h2);
    ans += sum;
    printf("%I64d\n", ans);
    //printf("%lld\n", ans);
}





D. Om Nom and Necklace
time limit per test
1 second
memory limit per test
256 megabytes

One day Om Nom found a thread with n beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly.

Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form aregular pattern. A sequence of beads S is regular if it can be represented asS = A + B + A + B + A + ... + A + B + A, whereA and B are some bead sequences, " + " is the concatenation of sequences, there are exactly2k + 1 summands in this sum, among which there arek + 1 "A" summands andk "B" summands that follow in alternating order. Om Nelly knows that her friend is an eager mathematician, so she doesn't mind ifA or B is an empty sequence.

Help Om Nom determine in which ways he can cut off the first several beads from the found thread (at least one; probably, all) so that they form aregular pattern. When Om Nom cuts off the beads, he doesn't change their order.

Input

The first line contains two integers n,k (1 ≤ n, k ≤ 1 000 000) — the number of beads on the thread that Om Nom found and numberk from the definition of the regular sequence above.

The second line contains the sequence of n lowercase Latin letters that represent the colors of the beads. Each color corresponds to a single letter.

Output

Print a string consisting of n zeroes and ones. Positioni (1 ≤ i ≤ n) must contain either number one if the firsti beads on the thread form a regular sequence, or a zero otherwise.

Sample test(s)
Input
7 2
bcabcab
Output
0000011
Input
21 2
ababaababaababaababaa
Output
000110000111111000011
Note

In the first sample test a regular sequence is both a sequence of the first 6 beads (we can takeA = "", B = "bca"), and a sequence of the first 7 beads (we can takeA = "b",B = "ca").

In the second sample test, for example, a sequence of the first 13 beads is regular, if we takeA = "aba",B = "ba".


题目大意:给一个长为n的字符串,对于其前缀子串,如果满足A+B+A+B+...+这样的形式,并且刚好有k+1个A和k个B,则对应位置值为1否则为0,注意A和B可能是空串


题目分析:非常纠结的一道题,首先想到的是枚举一个周期的串长,联想到kmp里的next数组的一个性质,即i - next[i]就表示长度为i的前缀串中的周期串的一个周期的串长,先求next数组,注意这里求的next数组和一般kmp里的next数组不太一样,因为这里对任意前缀串它的前后缀子串不能有重叠的部分,比如ababaa,如果在普通next数组里会是-1 0 0 1 2 3,而我们目标的next数组为-1 -1 0 1 2 0

s         a  b   a   b   a   a

i          0  1   2   3   4   5

next  -1  -1  0   1   2   0

len     1   2  2    2  2   5

next里第二个为-1是因为它对应的是当前位置,若是0的话则1-next[1] = 1显然周期串长为2(ab)

得到next数组后,我们要计算几个值,len表示周期串长,num表示周期,t表示周期不能被k整除的部分,可以发现若t==0,则肯定可以找到可行方案,因为整除的话,根据周期的可加性,例如k=2我们必然可以得到_A_A_这样的串,现在讨论t不等于0时,如果不是一个完整的周期串,t要加1,把周期去掉不能整除的部分再分成k份,若每份的个数小于t,则显然没有可行方案,反之存在可行方案



#include <cstdio>
#include <cstring>
int const MAX = 1e6 + 5;

char s[MAX];  
int next[MAX];  
int n, k;

void get_next()
{ 
    int j = -1; 
    next[0] = -1; 
    for(int i = 1; i < n; i++)
    { 
        while(j != -1 && s[j + 1] != s[i])
            j = next[j]; 
        if(s[j + 1] == s[i] ) 
            j++; 
        next[i] = j; 
    } 
}

int main() 
{
    scanf("%d %d %s", &n, &k, s);
    get_next();
    for(int i = 0; i < n; i++) 
    {
        int len = i - next[i];   
        int num = (i + 1) / len;   
        int t = num % k; 
        if(t == 0)
            printf("1");
        else
        {
            if(len * num != i + 1) 
                t ++;
            if((num - (num % k)) / k >= t) 
                printf("1");
            else 
                printf("0");
        }
    }
    printf("\n");
}

<think>我们正在处理用户的问题:RTX 4060笔记本通过Type-CDP1.4连接300Hz显示器,但游戏中刷新率只有144Hz。根据之前的分析,核心问题可能是带宽不足或配置不当。但这次用户明确使用了Type-CDP1.4,而Type-C接口如果支持DP Alt Mode,则可能直接输出DP信号,无通过USB协议换。因此,我们要重新审视连接方式。 关键点: 1. Type-CDP有两种情况: a) 使用被动线:此时Type-C接口必须支持DP Alt Mode,这样信号是原生的DP,不经过协议换,带宽取决于DP版本(1.4)和接口能力。 b) 使用主动换器:将USB信号换为DP信号,这种情况会受限于USB带宽(如USB 3.2 Gen 2x2的20Gbps),无法满足300Hz的求。 2. 用户使用的是“USB3.2DP1.4”还是“Type-C(DP Alt Mode)DP1.4”?根据用户第二次提问,明确是“Type-CDP1.4”,我们应假设是使用支持DP Alt Mode的线(被动线缆)。因此,理论上不会经过USB协议换,而是直接输出DP信号。 3. 但为什么仍然出现144Hz限制?可能的原因: - 笔记本Type-C接口不支持DP1.4,只支持到DP1.2(DP1.2最大支持1440p@165Hz,而300HzDP1.4)。 - 线DP线缆不是真正的DP1.4标准(比如只支持到DP1.2)。 - 显示器设置中未开启DP1.4模式(有些显示器要手动选择DP版本)。 - 系统或驱动设置问题,未正确识别300Hz。 4. RTX 4060笔记本Type-C接口通常支持DP1.4(因为RTX 40系列显卡支持DP1.4a),但要确认该Type-C接口是否支持DP Alt Mode以及具体版本。 解决方案步骤: 第一步:确认笔记本Type-C接口是否支持DP1.4 Alt Mode - 查看笔记本规格说明书或官网产品页,确认Type-C接口的视频输出能力。 - 如果支持Thunderbolt 3/4,则一定支持DP1.4(因为Thunderbolt包含DP Alt Mode)。 - 也可以通过设备管理器查看:在“通用串行总线控制器”中,如果有“USB 4”或“Thunderbolt”字样,则支持DP1.4。 第二步:检查线DP线- 确保线Type-C to DP)明确标注支持DP1.4和8K或4K@120Hz以上。 - 使用短线(不超过1.8米)以减少信号衰减。 - 如果可能,更换为知名品牌(如Cable Matters, Club3D)的线缆。 第三步:检查显示器设置 - 使用显示器物理按键进入OSD菜单,找到“输入设置”或类似选项,确认DP版本设置为DP1.4(有些显示器默认是DP1.2,要手动切换)。 - 关闭显示器的“自适应同步”或“FreeSync”功能(有时兼容性问题会导致刷新率受限),测试后再开启。 第四步:系统设置 -Windows显示设置中,确保刷新率设置为300Hz: 右键桌面 -> 显示设置 -> 高级显示设置 -> 选择显示器 -> 刷新率(选择300Hz) - 在NVIDIA控制面板中: 打开NVIDIA控制面板 -> 更改分辨率 -> 选择“PC”分辨率(非超高清、HD、SD)下的2560x1440 -> 刷新率选择300Hz。 如果300Hz不可见,尝试创建自定义分辨率(但谨慎,可能损坏显示器)。 第五步:更新驱动和固件 - 更新显卡驱动:从NVIDIA官网下载最新Game Ready驱动。 - 更新显示器固件:访问显示器官网,下载最新固件并按照说明更新。 - 更新笔记本Type-C控制器驱动(如果是Thunderbolt,则更新Thunderbolt驱动)。 第六步:检查游戏内设置 - 进入游戏,在图形设置中查找刷新率选项,手动设置为300Hz(有些游戏可能默认使用显示器的最高刷新率,但有时会选错)。 第七步:带宽计算与DSC(显示流压缩) - 2560x1440@300Hz所的带宽计算: 像素时钟 ≈ 2560 * 1440 * 300 * 1.2(空白间隔开销)≈ 1.33 G像素/秒 所带宽(未压缩)≈ 1.33 * 30(bpp,即每像素30位,8位色深下RGB为24位,加上其他开销)≈ 40 Gbps 而DP1.4的最大带宽为32.4 Gbps(HBR3速率,25.92Gbps有效带宽),因此必须依赖DSC(显示流压缩)才能实现。 - 确保显示器支持DSC,并在显示器的OSD菜单中开启(如果可设置)。 - 在NVIDIA控制面板中,查看“显示”->“更改分辨率”->“使用NVIDIA颜色设置”,确保“颜色格式”为RGB,且“输出颜色深度”为8bpc(10bpc或12bpc会增加带宽求,可能超过DSC的压缩能力)。 如果以上步骤都正确,但仍然无法达到300Hz,则可能是硬件限制(如笔记本Type-C接口实际只支持DP1.2)或线缆质量问题。 最后,如果所有设置都正确,但游戏内帧率无法达到300FPS(例如RTX 4060在1440p高画质下可能无法在3A大作中达到300FPS),那么刷新率会自动降级。此时要降低游戏画质或分辨率。 相关问题: 1. 如何检查笔记本Type-C接口是否支持DP Alt Mode? 2. 如何更新显示器固件? 3. 为什么DSC对高刷新率显示器至关重要? 4. 如何优化游戏设置以在1440p分辨率下获得更高帧率? 5. 哪些工具可以检测当前显示器的实际刷新率?</think>针对您的 RTX 4060 笔记本通过 **Type-C DP 1.4** 连接 2560x1440@300Hz 显示器时,游戏中刷新率被限制在 144Hz 的问题,以下是系统化的解决方案,基于技术规范和硬件限制分析: --- ### 一、核心问题诊断 1. **Type-C 接口的 DP Alt Mode 支持不足** - 笔记本Type-C 接口支持 **DP Alt Mode** 才能直接输出 DP 信号(而非通过 USB 协议换)[^2]。 - 若接口仅支持 USB 3.2 协议(带宽 20Gbps),而非纯 DP 模式,则无法满足 1440p@300Hz 的带宽求(约 32.67Gbps)[^1]。 - 此时系统会自动降级至 144Hz(带宽求约 15.68Gbps)。 2. **DP 1.4 带宽与 DSC 压缩问题** - DP 1.4 的理论带宽为 32.4Gbps(HBR3 模式)[^1],但 **2560x1440@300Hz 约 40Gbps**,必须依赖 **DSC(显示流压缩)** 技术。 - 若显示器/线缆/驱动未启用 DSC,刷新率会被限制在 144Hz。 3. **配置与兼容性问题** - 线缆或接器未达到 DP 1.4 标准 - 显示器未开启 DP 1.4 模式 - 游戏内垂直同步(VSync)或帧率限制设置 --- ### 二、解决方案步骤 #### ✅ 步骤 1:验证 Type-C 接口的 DP Alt Mode 支持 - **查看笔记本规格**:确认 Type-C 接口是否标注 **"DP" 或 "DisplayPort Alt Mode"**(非 Thunderbolt 接口可能仅支持 USB 协议)。 - **检测方法**: 1. 连接显示器后,进入 **NVIDIA 控制面板 → 更改分辨率 → PC 分辨率**。 2. 若可看到 **2560x1440@300Hz** 选项,说明接口支持 DP Alt Mode;若仅显示 144Hz,则为 USB 协议瓶颈。 #### ✅ 步骤 2:强制启用 DP 1.4 和 DSC - **显示器 OSD 设置**: 物理按键进入菜单 → 找到 **"DP 版本"** → 切换为 **DP 1.4**(部分显示器手动开启)。 - **启用 DSC**: 在显示器菜单中启用 **"Display Stream Compression (DSC)"**(若支持)。 - **Windows 设置**: `设置 → 系统 → 显示 → 高级显示 → 刷新率` → 手动选择 **300Hz**。 #### ✅ 步骤 3:更换高质量线缆与接器 - **线缆要求**: - 使用 **Type-C to DP 1.4 认证线缆**(如 Club3D / Cable Matters 品牌),长度 ≤1.5 米。 - 避免使用接器(易引入兼容性问题),优先选择直连线缆。 - **验证标准**:线明确标注 **"8K@60Hz" 或 "DP 1.4"**。 #### ✅ 步骤 4:更新驱动与固件 - **NVIDIA 显卡驱动**: 下载最新版驱动:[NVIDIA 官网](https://www.nvidia.com/Download/index.aspx) → 安装时勾选 **"清洁安装"**。 - **显示器固件**: 访问显示器官网(如 ASUS、Dell)下载固件更新工具。 - **USB/DP 控制器驱动**: 在设备管理器中更新 **"通用串行总线控制器"** 驱动。 #### ✅ 步骤 5:游戏与系统优化 - **NVIDIA 控制面板**: `管理 3D 设置 → 程序设置` → 选择游戏 → 设置: - **"首选刷新率" → 最高可用** - **"垂直同步" → 关闭** - **游戏内设置**: - 关闭垂直同步(VSync) - 手动设置刷新率为 **300Hz**(部分游戏在配置文件中修改)。 - **电源管理**: `Windows 电源计划 → 高性能模式`;NVIDIA 控制面板 → `电源管理模式 → 最高性能优先`。 --- ### 三、带宽验证与备选方案 1. **带宽求计算**: - 2560x1440@300Hz 所带宽: $$ \text{带宽} = 2560 \times 1440 \times 300 \times 10^{-9} \times 24\, \text{(色深)} \times 1.2\, \text{(开销)} \approx 40\, \text{Gbps} $$ - **DP 1.4 + DSC** 可压缩至 25 Gbps 内,满足求 [^1]。 2. **终极方案:使用原生 HDMI 2.1 接口** -笔记本有 HDMI 2.1 接口(带宽 48Gbps),直接连接显示器 HDMI 口,无接。 - 设置:`显示器输入源 → HDMI 2.1` → Windows 中选 300Hz。 --- ### 四、故障排除流程图 ```mermaid graph TD A[游戏内仅144Hz] --> B{检查Type-C接口模式} B -->|支持DP Alt Mode| C[启用DP1.4+DSC] B -->|仅USB模式| D[更换HDMI 2.1直连] C --> E[更新驱动/固件] E --> F[关闭垂直同步] F --> G[游戏内设300Hz] G --> H[成功输出300Hz] D --> H ``` > ⚠️ 若所有步骤无效,可能是硬件限制(如笔记本 Type-C 接口仅支持 DP 1.2),联系厂商确认规格。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值