首页 > 其他分享 >Coloring

Coloring

时间:2023-01-12 10:11:06浏览次数:71  
标签:case Coloring cells colors each test cases

题目链接

题目描述:

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 \(a_i\) 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 (1≤t≤10000)\) — the number of test cases. The description of test cases follows.

The first line of each test case contains three integers \(n\), \(m\), \(k (1≤k≤n≤10^9, 1≤m≤10^5, m≤n)\). 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 \(a_1,a_2,⋯,a_m (1≤a_i≤n)\) — the numbers of times that colors have to be used. It's guaranteed that \(a_1+a_2+…+a_m=n\).

It is guaranteed that the sum of \(m\) over all test cases does not exceed \(10^5\).

输出描述:

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;
}

标签:case,Coloring,cells,colors,each,test,cases
From: https://www.cnblogs.com/KSzsh/p/17045615.html

相关文章

  • CF1774B-Coloring
    挺有意思的一个思维题题面翻译Cirno_9baka的纸条上有\(n\)个格子,他觉得空白的纸条看着有点无趣,于是想在纸条的格子上涂上\(m\)种颜色。同时,他认为第\(i\)种颜色必......
  • UVA193 Graph Coloring - 一般图最大独立集 -
    题目链接:https://www.luogu.com.cn/problem/UVA193题解:注意不是二分图最大独立集和最大匹配没啥关系直接dfs//bySkyRainWind#include<bits/stdc++.h>#definempr......
  • 题解【CF1592F2 Alice and Recoloring 2】
    CF1592F2AliceandRecoloring2解题报告。不一定更好的阅读体验。摘自我的构造题目选做例题IV。CF2800的构造就这?/cf/cf/cf(首先,操作2和操作3都是没有用......
  • AtCoder Grand Contest 025B - RGB Coloring
    题解:一开始想把AA,BB,AA+B......
  • CF1027E Inverse Coloring
    考场上没敲出来(其实想到就挺好写的捏组数据手动模拟一下:\(\begin{bmatrix}1&0&1&1&1&0&1\\1&0&1&1&1&0&1\\0&1&0&0&0&1&0\\1&0&1&1&1&0&1\\0&1&0&0&0&1&0\\0......
  • CF149D Coloring Brackets
    题意:给出一串合法括号,按以下规则给括号染色:1.每个符号可以染红色、蓝色,或者不染色;2.相邻两个符号不能染同一种颜色,可以都不染色;3.一对括号有且仅有一个符号染色。求......
  • 【XSY3270】Domino Colorings(轮廓线dp,状压)
    若已经知道了每个格子的颜色,我们可以用轮廓线DP(类似插头DP)判断棋盘是否能被多米诺骨牌填满,设\(dp[S]\)表示是否存在某种填法使得轮廓线每个位置是否被填的状态为\(S\)......
  • CF1329A Dreamoon Likes Coloring 题解
    提供一个简短的题解:首先如果所有长度加起来还不到\(n\)直接无解。可以直接贪心,把第\(i\)条线段的右端点放在\(n-i+1\)这个位置,就可以最省长度(只占一个点)而且不会遗......
  • CF149D Coloring Brackets
    #include<bits/stdc++.h>usingnamespacestd;#defineintlonglongclasssolve{ public: chars[777]; intf[1000][1000][3][3]; intmod; intothers[1000......