[CSP-S Simulation Test]: sequence (configuration)

Title Description

Given $ N, A, B $, $ configured with a length of N $ arranged such that:
$ \ bullet arranged $ N $ length $;
$ \ $ bullet longest sequence length is increased $ A $;
$ \ bullet $ longest sequence length is decreased $ B $.
We have $ SPJ $, solvability any given group, no solution or explanation.


Input Format

A first line integer $ T (1 \ leqslant T \ leqslant 10) $, represents the number of data sets.
Then $ T $ lines of three positive integers $ N $, $ A $, $ B $.


Output Format

Each set of data:
if a solution, the output of two lines, the first line of a character string Yes $ $, $ N $ next line integers, indicates arrangement.
Otherwise, the output line of a string $ No $.


Sample

Sample input:

3
4 2 2
4 4 1
4 3 3

Sample output:

Yes
3 4 1 2
Yes
1 2 3 4
No


Data range and tips

For all of the test data to ensure that $ T \ leqslant 10, N \ leqslant 10 ^. 5, \ SUM N \ leqslant 2 \ Times 10 ^. 5
$ \ bullet $ subtask $ 1 $ ($ 20 $ points): $ N \ leqslant 5 $.
$ \ $ subtask bullet $ 2 $ ($ 30 $ points): each data satisfy the $ N = A \ times B $ .
$ \ bullet subtask $ $ $ 3 ($ 20 $ points): $ B \ leqslant 2 $ .
$ \ bullet $ subtasks $ 4 $ ($ 30 $ points): No special restrictions.


answer

A look that is a configuration problem, starting with $ N = A \ times B $ start, we can $ B $ sequence into blocks, so that the internal structure $ B $ block sequence length increase of $ A $, $ B $ block the sequence can be decreased with each other.

For chestnut, when $ N = 10, A = 2, B = 5 $, we can be configured to: $ (9,10), (7,8), (5,6), (3,4) , (1,2) $; it can be found within each small bracket upward, and the sequence between parentheses is decreased.

If not $ N = A \ times B $, then we can use this kind of thinking.

No $ $ last considered case, if $ A + B <N-1 $, then obviously not; if $ A \ times B <N $ is not acceptable.

So to this problem was solved.

Time complexity: $ \ Theta (N) $.

Expectations score: $ 100 $ points.

Actual score: $ 100 $ points.


Code time

#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int T;scanf("%d",&T);
	while(T--)
	{
		int N,A,B;scanf("%d%d%d",&N,&A,&B);
		if(N<A+B-1||N>1LL*A*B){puts("No");continue;}
		int len=N-B;puts("Yes");
		for(int i=1;i<=B;i++)
		{
			int now=1;
			while(now<A&&len){len--;now++;}
			for(int j=N-now+1;j<=N;j++)printf("%d ",j);
			N-=now;
		}puts("");
	}
	return 0;
}

rp ++

Guess you like

Origin www.cnblogs.com/wzc521/p/11689814.html