bnuz训练B D E

B
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.

The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.

A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let’s call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of 7 because its subribbon a appears 7 times, and the ribbon abcdabc has the beauty of 2 because its subribbon abc appears twice.

The rules are simple. The game will have n turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after n turns wins the treasure.

Could you find out who is going to be the winner if they all play optimally?

Input
The first line contains an integer n (0≤n≤109) — the number of turns.

Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than 105 uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.

Output
Print the name of the winner (“Kuro”, “Shiro” or “Katie”). If there are at least two cats that share the maximum beauty, print “Draw”.

#include
#include
int main() {
     
	long long n,ans = 0,flag,temp[]= {
     0,0,0},m[123] = {
     0};
	char a[100100];
	while(~scanf("%lld",&n)) {
     
		flag = 0;
		for(int i = 0; i < 3; i ++) {
     
			memset(m,0,sizeof(m));
			scanf("%s",a);
			int max = 0,sum = 0,len = strlen(a);
			for(int j = 0; j < len; j ++) {
     
				m[a[j]] ++;
			}
			for(int k = 65; k <= 122; k ++) {
     
				if(m[k] > max)
					max = m[k];
			}
			if(n==1 && max == len)
            	temp[i] = len-1;
        	else temp[i] = max+n > len ? len : max + n;			
		}
		ans = 0;
		for(int i = 0; i < 3; i ++) {
     
			if(ans < temp[i]) {
     
				flag = i;
				ans = temp[i];
			}
		}
		for(int i = 0; i < 3; i ++) {
     
			if(temp[i] == ans && i != flag)
				flag = -1;
		}
		if(flag == 0)
			printf("Kuro\n");
		else if(flag == 1)
			printf("Shiro\n");
		else if(flag == 2)
			printf("Katie\n");
		else
			printf("Draw\n");
	}
	return 0;
}

D
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.

Little Tommy has n lanterns and Big Banban has m lanterns. Tommy’s lanterns have brightness a1, a2, …, an, and Banban’s have brightness b1, b2, …, bm respectively.

Tommy intends to hide one of his lanterns, then Banban picks one of Tommy’s non-hidden lanterns and one of his own lanterns to form a pair. The pair’s brightness will be the product of the brightness of two lanterns.

Tommy wants to make the product as small as possible, while Banban tries to make it as large as possible.

You are asked to find the brightness of the chosen pair if both of them choose optimally.

Input
The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 50).

The second line contains n space-separated integers a1, a2, …, an.

The third line contains m space-separated integers b1, b2, …, bm.

All the integers range from  - 109 to 109.

Output
Print a single integer — the brightness of the chosen pair.

思路:对数组一排序,把前两个数和后两个数分别与数组二最大最小相乘比较,输出第二大的数

#include

int main() {
     
	int n,m;
	long long a[55],b[55];
	while(~scanf("%d%d",&n,&m)) {
     
		long long i,j = 0,max,min;
		for(i = 0; i < n; i ++) {
     
			scanf("%lld",&a[i]);
		}
		for(i = 0; i < n-1; i ++) {
     
			for(j = 0; j < n - i - 1; j ++)
				if(a[j] < a[j+1])
					a[j] ^= a[j+1] ^= a[j] ^= a[j+1];
		}
		for(i = 0; i < m; i ++) {
     
			scanf("%lld",&b[i]);
			if(!i) {
     
				max = b[i];
				min = b[i];
			}
			if(max < b[i]) {
     
				max = b[i];
			}
			if(min > b[i])
				min = b[i];
		}
		if(n == 2) {
     
			long long p,q,ans;
			p = (a[0]*max > a[0]*min) ? a[0]*max : a[0]*min;
			q = (a[1]*max > a[1]*min) ? a[1]*max : a[1]*min;
			ans = q < p ? q : p;
			printf("%lld\n",ans);	
		} else {
     
			long long o[4];
			o[0] = (a[0]*max > a[0]*min) ? a[0]*max : a[0]*min;
			o[1] = (a[1]*max > a[1]*min) ? a[1]*max : a[1]*min;
			o[2] = (a[n-2]*max > a[n-2]*min) ? a[n-2]*max : a[n-2]*min;
			o[3] = (a[n-1]*max > a[n-1]*min) ? a[n-1]*max : a[n-1]*min;
			for(i = 0; i < 4 - 1; i ++) {
     
				for(j = 0; j < 4 - 1 - i; j ++) {
     
					if(o[j] < o[j + 1])
						o[j] ^= o[j+1] ^= o[j] ^= o[j+1];
				}
			}
			printf("%lld\n",o[1]);

		}
	}
}

E
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.

Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.

He would like to find a positive integer n not greater than 1018, such that there are exactly k loops in the decimal representation of n, or determine that such n does not exist.

A loop is a planar area enclosed by lines in the digits’ decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms.

Input
The first and only line contains an integer k (1 ≤ k ≤ 106) — the desired number of loops.

Output
Output an integer — if no such n exists, output -1; otherwise output any such n. In the latter case, your output should be a positive decimal integer not exceeding 1018.

#include

int main() {
     
	long long n;
	while(~scanf("%lld",&n)) {
     
		if(n > 36)
			printf("-1\n");
		else {
     
			if(n % 2) {
     
				printf("6");
				n--;
			}
			if(n < 2)
				break;
			do {
     
				printf("8");
			} while(n-=2);
			printf("\n");
		}
	}
	return 0;
}

你可能感兴趣的:(bnuz训练B D E)