KSzsh

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

Coloring

题目链接

题目描述:

Cirno_9baka has a paper tape with n cells in a row on it. As he thinks that the blank paper tape is too dull, he wants to paint these cells with m kinds of colors. For some aesthetic reasons, he thinks that the i-th color must be used exactly ai times, and for every k consecutive cells, their colors have to be distinct.

Help Cirno_9baka to figure out if there is such a way to paint the cells.

输入描述:

The first line contains a single integer t(1t10000) — the number of test cases. The description of test cases follows.

The first line of each test case contains three integers n, m, k(1kn109,1m105,mn). Here n denotes the number of cells, m denotes the number of colors, and k means that for every k consecutive cells, their colors have to be distinct.

The second line of each test case contains m integers a1,a2,,am(1ain) — the numbers of times that colors have to be used. It's guaranteed that a1+a2++am=n.

It is guaranteed that the sum of m over all test cases does not exceed 105.

输出描述:

For each test case, output "YES" if there is at least one possible coloring scheme; otherwise, output "NO".

You may print each letter in any case (for example, "YES", "Yes", "yes", and "yEs" will all be recognized as positive answers).

样例:

input:

2
12 6 2
1 1 1 1 1 7
12 6 2
2 2 2 2 2 2

output:

NO
YES

Note:

In the first test case, there is no way to color the cells satisfying all the conditions.

In the second test case, we can color the cells as follows: (1,2,1,2,3,4,3,4,5,6,5,6). For any 2 consecutive cells, their colors are distinct.

AC代码:

#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
// x 代表将 n 分为 k 段, y 代表最后不足 k 的长度
int x = n / k, y = n % k;
bool f = 1;
while (m--)
{
int a;
scanf("%d", &a);
// 颜色需要涂的次数如果小于 x 就代表可以把这个颜色涂在 a 个段里
if (a <= x)
continue;
// 如果大于x就代表需要用到最后那一段
// 如果最后一段有剩余并且只会占用一格的话就说明可以涂完
// 否则则要占用大于一格或者最后一段已经被涂满,不满足没有相同颜色
if (a == x + 1 && y)
y--;
else
f = 0;
}
if (f)
cout << "YES\n";
else
cout << "NO\n";
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
solve();
return 0;
}

posted on   KSzh  阅读(99)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
点击右上角即可分享
微信分享提示