Codeforces 8VC Venture Cup 2016 - Elimination Round解题报告

实际上苟蒻只会做四题。。

A. Robot Sequence
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the same square he starts in? Two substrings are considered different if they have different starting or ending indices.

Input

The first line of the input contains a single positive integer, n (1 ≤ n ≤ 200) — the number of commands.

The next line contains n characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code.

Output

Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square.

Examples
input
6
URLLDR
output
2
input
4
DLUU
output
0
input
7
RLRLRLR
output
12
Note

In the first case, the entire source code works, as well as the "RL" substring in the second and third characters.

Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result.


题意:
某机器人可以按上下左右移动。。。现给出一串指令,机器人所处空间无限大,问有多少该指令的某一连续子串,使得机器人执行后回原位


暴力不说了。。。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

const int maxn = 210;

char c[maxn];
int n,ans = 0,x,y;

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif
	
	cin >> n;
	cin >> c;
	for (int i = 0; i < n; i++)
		for (int j = i; j < n; j++) {
			x = y = 0;
			for (int l = i; l <= j; l++) {
				if (c[l] == 'U') ++y;
				else if (c[l] == 'D') --y;
				else if (c[l] == 'L') --x;
				else ++x;
			}
			if (!x && !y) ++ans;
		}
	cout << ans;
	return 0;
}


B. Cards
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:

  • take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color;
  • take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.

She repeats this process until there is only one card left. What are the possible colors for the final card?

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200) — the total number of cards.

The next line contains a string s of length n — the colors of the cards. s contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.

Output

Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.

Examples
input
2
RB
output
G
input
3
GRG
output
BR
input
5
BBBBB
output
B
Note

In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.

In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.

In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.


题意:

Catherine有n张卡片,每张卡片分别是蓝绿红的其中一种颜色每次可以执行两种操作中的一种:

1:将两张同色卡片换成一张该颜色卡

2:将两张异色卡片换成一张第三种颜色卡

问:最后剩的一张卡可能是什么颜色


所有情况都讨论一遍就好。。。


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

int b,g,r,n;
char c[210];

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif
	
	cin >> n >> c;
	for (int i = 0; i < n; i++) {
		if (c[i] == 'B') ++b;
		else if (c[i] == 'G') ++g;
		else ++r;
	}
	
	if (b && g && r) {
		printf("BGR");
		return 0;
	}
	if (!b && !g) {
		printf("R");
		return 0;
	}
	if (!b && !r) {
		printf("G");
		return 0;
	}
	if (!g && !r) {
		printf("B");
		return 0;
	}
	if (!b) {
		if (g > 1 && r > 1) {
			printf("BGR");
			return 0;
		}
		if (g == 1 && r == 1) {
			printf("B");
			return 0;
		}
		if (g == 1) {
			printf("BG");
			return 0;
		}
		else {
			printf("BR");
			return 0;
		}
	}
	if (!g) {
		if (b > 1 && r > 1) {
			printf("BGR");
			return 0;
		}
		if (b == 1 && r == 1) {
			printf("G");
			return 0;
		}
		if (b == 1) {
			printf("BG");
			return 0;
		}
		else {
			printf("GR");
			return 0;
		}
	}
	if (b > 1 && g > 1) {
		printf("BGR");
		return 0;
	}
	if (b == 1 && g == 1) {
		printf("R");
		return 0;
	}
	if (b == 1) {
		printf("BR");
		return 0;
	}
	else {
		printf("GR");
		return 0;
	}
	return 0;
}

C. Block Towers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.

The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

Input

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000n + m > 0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Output

Print a single integer, denoting the minimum possible height of the tallest tower.

Examples
input
1 3
output
9
input
3 2
output
8
input
5 0
output
10
Note

In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 36, and 9 blocks. The tallest tower has a height of 9 blocks.

In the second case, the students can make towers of heights 24, and 8 with two-block pieces and towers of heights 3 and 6 with three-block pieces, for a maximum height of 8 blocks.


题意:

好多小孩在玩建塔游戏。。。其中一队只有高度为2的积木,另一队只有高度为3的积木,他们都不喜欢自己建的塔的高度和其他小孩一样,问满足条件情况下最高的塔的高度最低是多少


对于任意i,记

a1:小于等于i的所有数中是2的倍数但不是6的倍数的数

a2:小于等于i的所有数中是3的倍数但不是6的倍数的数

a3:小于等于i的所有数中是6的倍数的数

若a1+a2+a3 >= n+m 则i是解


答案挺小的。。。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

const int maxn = 1E6 + 10;

int ar[maxn*3],n,m,tw,tr;

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif
	
	cin >> n >> m;
	
	for (int i = 1; ; i++) {
		int a1 = max(n - (i/2 - i/6),0);
		int a2 = max(m - (i/3 - i/6),0);
		int a3 = i/6;
		if (a1 + a2 <= a3) {
			cout << i;
			return 0;
		}
	}
	return 0;
}


D. Jerry's Protest
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds.

Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew?

Input

The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar.

The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number.

Output

Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

Examples
input
2
1 2
output
0.0000000000
input
3
1 2 10
output
0.0740740741
Note

In the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total.

In the second case, each game could've had three outcomes — 10 - 210 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability .



题意:

Andrew and Jerry 正在玩一种游戏。。。现有一个瓶子里面装着n个球,每个球有一个编号,每次两人分别从瓶里拿出一个球,编号大的人获胜,然后将球放回。一共三局,三局两胜。Andrew总能赢得前两局,于是Jerry不乐意了,他想知道他有多大概率,使得三次编号和大于Andrew的


题解:

因为胜利是固定属于一方,所以枚举出所有胜利方式,约n^2种,每次是这里面的一种。注意到胜利方的分数能比失败方多(废话。。。)于是通过这两数只差建立数组a,记a[i]为胜利方比失败方多i分的方案数,显然,1<=i<5000,于是我们可以枚举前两局情况,得出答案


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

const int maxn = 2E3 + 10;
typedef double DB;

int n,num[maxn];
DB ans = 0,cur = 0,sum[3*maxn],a[3*maxn];

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif
	
	cin >> n;
	for (int i = 0; i  < n; i++) scanf("%d",&num[i]);
	sort (num,num + n);
	int cur = 0;
	for (int i = n - 1; i; i--)
		for (int j = i - 1; j >= 0; j--) {
			cur += 1; a[num[i] - num[j]] += 1;
		}
	//cur = cur*cur*cur;
	for (int i = 5000; i; i--) sum[i] = a[i] + sum[i+1];
	for (int i = 1; i <= 5000; i++) a[i] /= cur, sum[i] /= cur;
	for (int i = 1; i < 5000; i++)
		for (int j = 1; j < 5000; j++) 
			if (i + j < 5000) {
				int x = i + j + 1;
				ans += sum[x]*a[i]*a[j];
			}
	printf("%.12f",ans);
	return 0;
}

E. Simple Skewness
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness.

The mean of a collection is the average of its elements. The median of a collection is its middle element when all of its elements are sorted, or the average of its two middle elements if it has even size.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of elements in the list.

The second line contains n integers xi (0 ≤ xi ≤ 1 000 000) — the ith element of the list.

Output

In the first line, print a single integer k — the size of the subset.

In the second line, print k integers — the elements of the subset in any order.

If there are multiple optimal subsets, print any.

Examples
input
4
1 2 3 12
output
3
1 2 12 
input
4
1 1 2 2
output
3
1 1 2 
input
2
1 2
output
2
1 2
Note

In the first case, the optimal subset is , which has mean 5, median 2, and simple skewness of 5 - 2 = 3.

In the second case, the optimal subset is . Note that repetition is allowed.

In the last case, any subset has the same median and mean, so all have simple skewness of 0.


题意:

从给定的n个数中选任意个数组成可重集,输出一种使得排序后其平均值-中位数最大的方案


题解:

苟蒻其实是不会做的。。。显然可以排除偶数的方案(我不知道为什么)然后,对于奇数方案,枚举中位数及个数,使得平均值最大的集合显然确定,然后这玩意是可以三分的。。。。。。。


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

const int maxn = 2E5 + 10;

typedef long long LL;
typedef double DB;

LL num[maxn],sum[maxn];
int n,pos,cnt;
DB MAX = 0;

DB solve(int i,int x)
{
	DB avg = (DB)(sum[i-1] - sum[i-1-x] + num[i] + sum[n] - sum[n-x])/(DB)(2*x + 1);
	if (avg - (DB)(num[i]) > MAX) {
		MAX = avg - (DB)(num[i]);
		pos = i; cnt = x;
	}
	return avg - (DB)(num[i]);
}

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i <= n; i++) scanf("%I64d",&num[i]);
	sort (num + 1,num + n + 1);
	for (int i = 1; i <= n; i++) sum[i] = num[i] + sum[i-1];
	pos = 1;
	
	for (int i = 1; i <= n; i++) {
		int L = 0,R = min(i-1,n-i);
		while (R - L > 2) {
			int mid1 = L + (R-L)/3;
			int mid2 = R - (R-L)/3;
			if (solve(i,mid1) > solve(i,mid2)) R = mid2;
			else L = mid1;
		}
		solve(i,L); solve(i,R);
		if (R - L > 1) solve(i,L+1);
	}
	
	printf("%d\n",cnt*2 + 1);
	for (int i = pos-cnt; i <=pos; i++) printf("%d ",num[i]);
	for (int i = n; i > n-cnt; i--) printf("%d ",num[i]);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值