Codeforces Round #634 (Div. 3)部分题解(A&&B)

Candies and Two Sisters CodeForces - 1335A
There are two sisters Alice and Betty. You have n candies. You want to distribute these n candies between two sisters in such a way that:

Alice will get a (a>0) candies;
Betty will get b (b>0) candies;
each sister will get some integer number of candies;
Alice will get a greater amount of candies than Betty (i.e. a>b);
all the candies will be given to one of two sisters (i.e. a+b=n).
Your task is to calculate the number of ways to distribute exactly n candies between sisters in a way described above. Candies are indistinguishable.

Formally, find the number of ways to represent n as the sum of n=a+b, where a and b are positive integers and a>b.

You have to answer t independent test cases.

Input
The first line of the input contains one integer t (1≤t≤104) — the number of test cases. Then t test cases follow.

The only line of a test case contains one integer n (1≤n≤2⋅109) — the number of candies you have.

Output
For each test case, print the answer — the number of ways to distribute exactly n candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print 0.

Example
Input
6
7
1
2
3
2000000000
763243547
Output
3
0
0
1
999999999
381621773
Note
For the test case of the example, the 3 possible ways to distribute candies are:

a=6, b=1;
a=5, b=2;
a=4, b=3.
思路:水题,直接输出(n+1)/2-1就可以了。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		ll n;
		cin>>n;
		cout<<((n+1ll)/2ll-1ll)<<endl;
	}
	return 0;
}

Construct the String CodeForces - 1335B
You are given three positive integers n, a and b. You have to construct a string s of length n consisting of lowercase Latin letters such that each substring of length a has exactly b distinct letters. It is guaranteed that the answer exists.

You have to answer t independent test cases.

Recall that the substring s[l…r] is the string sl,sl+1,…,sr and its length is r−l+1. In this problem you are only interestd in substrings of length a.

Input
The first line of the input contains one integer t (1≤t≤2000) — the number of test cases. Then t test cases follow.

The only line of a test case contains three space-separated integers n, a and b (1≤a≤n≤2000,1≤b≤min(26,a)), where n is the length of the required string, a is the length of a substring and b is the required number of distinct letters in each substring of length a.

It is guaranteed that the sum of n over all test cases does not exceed 2000 (∑n≤2000).

Output
For each test case, print the answer — such a string s of length n consisting of lowercase Latin letters that each substring of length a has exactly b distinct letters. If there are multiple valid answers, print any of them. It is guaranteed that the answer exists.

Example
Input
4
7 5 3
6 1 1
6 6 1
5 2 2
Output
tleelte
qwerty
vvvvvv
abcde
Note
In the first test case of the example, consider all the substrings of length 5:

“tleel”: it contains 3 distinct (unique) letters,
“leelt”: it contains 3 distinct (unique) letters,
“eelte”: it contains 3 distinct (unique) letters.
思路:b有多少,一串字符串就有几个。例如b=5,那么这一串就是abcde,然后这样一串一串的拼成n长度的就可以了。a没用。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int n,a,b;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d%d",&n,&a,&b);
		int cnt=0;
		while(1)
		{
			if(n<=b) 
			{
				for(int i=0;i<n;i++) cout<<(char)(cnt+'a'),cnt++;
				break;
			}
			for(int i=0;i<b;i++) cout<<(char)(cnt+'a'),cnt++;
			cnt=0;
			n-=b;
		}
		cout<<endl;
	}
	return 0;
}

努力加油a啊,(o)/~

发布了668 篇原创文章 · 获赞 118 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/starlet_kiss/article/details/105528640