Codeforces Round #643 (Div. 2)

这场是七点半的场,正好跑完步打了一下 于是:
Codeforces Round #643 (Div. 2)_第1张图片
在这里插入图片描述
害 还是太菜了

A - Sequence with Digits

Let’s define the following recurrence:
an+1=an+minDigit(an)⋅maxDigit(an).
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.

Your task is calculate aK for given a1 and K.

Input
The first line contains one integer t (1≤t≤1000) — the number of independent test cases.

Each test case consists of a single line containing two integers a1 and K (1≤a1≤1018, 1≤K≤1016) separated by a space.

Output
For each test case print one integer aK on a separate line.

Example
Input
8
1 4
487 1
487 2
487 3
487 4
487 5
487 6
487 7
Output
42
487
519
528
544
564
588
628
Note
a1=487

a2=a1+minDigit(a1)⋅maxDigit(a1)=487+min(4,8,7)⋅max(4,8,7)=487+4⋅8=519

a3=a2+minDigit(a2)⋅maxDigit(a2)=519+min(5,1,9)⋅max(5,1,9)=519+1⋅9=528

a4=a3+minDigit(a3)⋅maxDigit(a3)=528+min(5,2,8)⋅max(5,2,8)=528+2⋅8=544

a5=a4+minDigit(a4)⋅maxDigit(a4)=544+min(5,4,4)⋅max(5,4,4)=544+4⋅5=564

a6=a5+minDigit(a5)⋅maxDigit(a5)=564+min(5,6,4)⋅max(5,6,4)=564+4⋅6=588

a7=a6+minDigit(a6)⋅maxDigit(a6)=588+min(5,8,8)⋅max(5,8,8)=588+5⋅8=628

题意

给你一个a1和n 根据公式a2 = a1 + (a1各位数中最小值)*(a1各位数中最大值)求出第n项

思路

//519 528 544 564 588 628 644 664 688 728
//1 2 6 42 50 50 50 50 50
//2 6 42 50
//3 12 15 20
//4 20
//5 30
//6 42
//7 56 86 132 135 140
//8 72 86 132 135 140
//9 90
//10
//11 12 14 18 26 38 62 74 102
//12 14 18
//13 16 22 26
//11111 11112 11113 11114 11115 … 11120
//22222 22226 22238 22254 22264 22276 22290
经过十来分钟的模拟,我发现我找的例子无论是多少都能很快的出现0,一旦出现0,往后的值就都是一样的了,于是就可以直接算,一直算到有0退出,大胆猜想每次都很快退出,于是不会超时

代码

#include 
using namespace std;
typedef long long ll;

ll min_n(ll x)
{
	ll ans = 1000;
	while(x)
	{
		ans = min(x%10,ans);
		x /= 10;
	}
	return ans;
}

ll max_n(ll x)
{
	ll ans = 0;
	while(x)
	{
		ans = max(x%10,ans);
		x /= 10;
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(0);
	int T;
	cin>>T;
	while(T--)
	{
		ll n,k;
		cin>>n>>k;
		k--;
		while(k--)
		{
			ll now1 = min_n(n);
			ll now2 = max_n(n);
			if(!now1) break;
			n += now1*now2;
		}
		cout<<n<<"\n";
	}
}

B - Young Explorers

Young wilderness explorers set off to their first expedition led by senior explorer Russell. Explorers went into a forest, set up a camp and decided to split into groups to explore as much interesting locations as possible. Russell was trying to form groups, but ran into some difficulties…

Most of the young explorers are inexperienced, and sending them alone would be a mistake. Even Russell himself became senior explorer not long ago. Each of young explorers has a positive integer parameter ei — his inexperience. Russell decided that an explorer with inexperience e can only join the group of e or more people.

Now Russell needs to figure out how many groups he can organize. It’s not necessary to include every explorer in one of the groups: some can stay in the camp. Russell is worried about this expedition, so he asked you to help him.

Input
The first line contains the number of independent test cases T(1≤T≤2⋅105). Next 2T lines contain description of test cases.

The first line of description of each test case contains the number of young explorers N (1≤N≤2⋅105).

The second line contains N integers e1,e2,…,eN (1≤ei≤N), where ei is the inexperience of the i-th explorer.

It’s guaranteed that sum of all N doesn’t exceed 3⋅105.

Output
Print T numbers, each number on a separate line.

In i-th line print the maximum number of groups Russell can form in i-th test case.

Example
Input
2
3
1 1 1
5
2 3 1 2 2
Output
3
2
Note
In the first example we can organize three groups. There will be only one explorer in each group. It’s correct because inexperience of each explorer equals to 1, so it’s not less than the size of his group.

In the second example we can organize two groups. Explorers with inexperience 1, 2 and 3 will form the first group, and the other two explorers with inexperience equal to 2 will form the second group.

This solution is not unique. For example, we can form the first group using the three explorers with inexperience equal to 2, and the second group using only one explorer with inexperience equal to 1. In this case the young explorer with inexperience equal to 3 will not be included in any group.

题意

有N个探险家,每个探险家的经验值为Ei 每个探险家可以加入队伍,但是每个人的经验值不大于他在组的人数,最大化组数

思路

排序然后从左往右贪心选就完事,个人认为比A题简单

代码

#include 
using namespace std;
const int maxn = 200000+1000;
int a[maxn],bk[maxn];
int main()
{
	ios::sync_with_stdio(0);
	int T;
	cin>>T;
	while(T--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i],bk[a[i]]++;
		sort(a+1,a+1+n);
		int ans = 0;
		int now = 1;
		for(int i=1;i<=n;i++)
		{
			if(a[i]<=now )
			ans++,now=1;
			else
			now ++;
		}
		cout<<ans<<"\n";
	}
}

D - Game With Array

Petya and Vasya are competing with each other in a new interesting game as they always do.

At the beginning of the game Petya has to come up with an array of N positive integers. Sum of all elements in his array should be equal to S. Then Petya has to select an integer K such that 0≤K≤S.

In order to win, Vasya has to find a non-empty subarray in Petya’s array such that the sum of all selected elements equals to either K or S−K. Otherwise Vasya loses.

You are given integers N and S. You should determine if Petya can win, considering Vasya plays optimally. If Petya can win, help him to do that.

Input
The first line contains two integers N and S (1≤N≤S≤106) — the required length of the array and the required sum of its elements.

Output
If Petya can win, print “YES” (without quotes) in the first line. Then print Petya’s array in the second line. The array should contain N positive integers with sum equal to S. In the third line print K. If there are many correct answers, you can print any of them.

If Petya can’t win, print “NO” (without quotes).

You can print each letter in any register (lowercase or uppercase).

Examples
Input
1 4
Output
YES
4
2
Input
3 4
Output
NO
Input
3 8
Output
YES
2 1 5
4

题意

Petya and Vasya两个人玩游戏,刚开始给你N和S,Petya要先构造一个数列,这个数列的和等于S而且数量等于N,并且给出一个数字K。Vasya如果想赢必须从Petya给定的数列里面选出几个数,让它们的和等于K或者S-K,如果不行就是Petya赢了。如果Petya能赢(必胜)那就输出YES并且输出Petya给出的数列和数字K 否则输出NO

思路

只需要构造数列1 1 1 1 1 1 …S-(n-1) 即可,然后Petya选择数字N(1的个数+1)当作K,这样一来无论如何Vasya都无法取出和等于K或者S-K的序列来。如果不能构造我就输出了NO ,具体为什么无法证明。

代码

#include 
using namespace std;
int main()
{
	int n,s;
	cin>>n>>s;
	int f = 0,ans = 0;
	for(int i=0;i<s+1;i++)
	{
		if(i>n-1 && i<s-(n-1))
		{
			f = 1;
			ans = i;
			break;
		}
	}
	if(!f)
	cout<<"NO";
	else
	{
		cout<<"YES\n";
		for(int i=1;i<=n-1;i++)
		cout<<"1 ";
		cout<<s-(n-1)<<"\n";
		cout<<ans;
	}
} 

你可能感兴趣的:(题解)