Educational Codeforces Round 90

Posted tecode

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 90相关的知识,希望对你有一定的参考价值。

A. Donut Shops

There are two rival donut shops.

The first shop sells donuts at retail: each donut costs a dollars.

The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x.

You want to determine two positive integer values:

how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop?
how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop?
If any of these values doesn‘t exist then that value should be equal to ?1. If there are multiple possible answers, then print any of them.

The printed values should be less or equal to 109. It can be shown that under the given constraints such values always exist if any values exist at all.

Input
The first line contains a single integer t (1≤t≤1000) — the number of testcases.

Each of the next t lines contains three integers a, b and c (1≤a≤109, 2≤b≤109, 1≤c≤109).

Output
For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 109.

If there is no such x, then print ?1. If there are multiple answers, then print any of them.

Example

input

4
5 10 4
4 5 20
2 2 3
1000000000 1000000000 1000000000

output

-1 20
8 -1
1 2
-1 1000000000

Note

In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you‘ll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you‘ll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers.

In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops.

In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop.

In the fourth testcase 109 donuts cost 1018 dollars in the first shop and 109 dollars in the second shop.

题意: A 店每个甜甜圈 a 元 ,B 店一盒 b 个甜甜圈 c 元 ,输出 x 表示在该店买 x 个甜甜圈比另一家店便宜 .(B店只能一盒一盒购买)

每个案例对应 a b c ,若不存在 x 则输出 -1 .

分类讨论:

记 ans1 ,ans2 为答案 .

b == 1 时 ,比较 a 和 c 的大小即可 .

b != 1 时 ,A 店也买 b 个甜甜圈价钱为 a * b;

若 a * b <= c ,则另 ans1 = 1 ,ans2 = -1;

若 a * b > c ,则 ans2 = b; 若 a < c ,则 ans1 = 1; 否则 a >= c 时 ans1 = -1;

这...和直接贴代码有什么区别...

#include <bits/stdc++.h>
#define LL long long
#define Pi acos(-1.0)
#define INF 2147483646
#define eps 1e-9
#define MS 100009
#define mss 17
using namespace std;
// Notice the data size
// Notice the input and output 
 
LL n,m,k;
LL p[MS];
 
int main() {
	cin >> k;
	while(k--){
		LL a,b,c;
		cin >> a >> b >> c;
		LL ans1,ans2;
		if(b == 1){
			if(a == c){
				ans1 = ans2 = -1;
			}
			else if(a > c){
				ans1 = 1;
				ans2 = -1;
			}
			else if(a < c){
				ans1 = -1;
				ans2 = 1;
			}
		}
		else{
			if(a*b<=c){
				ans1 = 1;
				ans2 = -1;
			}
			else if(a*b>c){
				ans2 = b;
				if(a<c){
					ans1 = 1;
				}
				else ans1 = -1;
			}
		}
		printf("%lld %lld
",ans1,ans2);
	} 
	
	
	return 0;
}

B. 01 Game

Alica and Bob are playing a game.

Initially they have a binary string s consisting of only characters 0 and 1.

Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent characters of string s and delete them. For example, if s=1011001 then the following moves are possible:

delete s1 and s2: 1011001→11001;
delete s2 and s3: 1011001→11001;
delete s4 and s5: 1011001→10101;
delete s6 and s7: 1011001→10110.

If a player can‘t make any move, they lose. Both players play optimally. You have to determine if Alice can win.

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

Only line of each test case contains one string s (1≤|s|≤100), consisting of only characters 0 and 1.

Output
For each test case print answer in the single line.

If Alice can win print DA (YES in Russian) in any register. Otherwise print NET (NO in Russian) in any register.

Example

input

3
01
1111
0011

output

DA
NET
NET

Note
In the first test case after Alice‘s move string s become empty and Bob can not make any move.

In the second test case Alice can not make any move initially.

In the third test case after Alice‘s move string s turn into 01. Then, after Bob‘s move string s become empty and Alice can not make any move.

题意:两玩家 ,Alice先 ,Bob后 ,每次能做的操作为找到相邻的两个‘0‘、‘1‘字符并删除 ,最后不能操作的人输 .

若Alice赢 ,则输出 ‘DA‘ ,否则 ‘NET‘ . (俄语中分别表示 YES 和 NO ) .

解: 只要字符串中有 0 有 1 则游戏都可以进行下去 ,而且每次操作必定少一个 0 和 1 ,则得到 0 和 1 中少的个数记为 t ,t 为奇数则赢 .

#include <bits/stdc++.h>
#define LL long long
#define Pi acos(-1.0)
#define INF 2147483646
#define eps 1e-9
#define MS 100009
#define mss 17
using namespace std;
// Notice the data size

LL n,m,k;
LL p[MS];
char s[MS];

int main() {
	std::ios::sync_with_stdio(false);
	cin >> k;
	while(k--){
		memset(s,0,sizeof s);
		cin >> s;
		LL t1,t0,h = strlen(s);
		t0 = t1 = 0;
		for(int i=0;i<h;i++){
			if(s[i] == ‘0‘) t0++;
			else t1++;
		}
		LL t = min(t0,t1);
		if(t&1){
			printf("DA
");
		}
		else printf("NET
");
	}
	
	
	return 0;
}

C. Pluses and Minuses

You are given a string s consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode:

res = 0
for init = 0 to inf
    cur = init
    ok = true
    for i = 1 to |s|
        res = res + 1
        if s[i] == ‘+‘
            cur = cur + 1
        else
            cur = cur - 1
        if cur < 0
            ok = false
            break
    if ok
        break

Note that the inf denotes infinity, and the characters of the string are numbered from 1 to |s|.

You have to calculate the value of the res after the process ends.

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

The only lines of each test case contains string s (1≤|s|≤106) consisting only of characters + and -.

It‘s guaranteed that sum of |s| over all test cases doesn‘t exceed 106.

Output
For each test case print one integer — the value of the res after the process ends.

Example

input

3
--+-
---
++--+-

output

7
9
6

题意: 就是题中所给代码最后得到 res 的值 .

翻译一下就比如一个横板2D闯关游戏 ,一开始血量 cur = 0 ,每一格对应一个字符 ,每次碰到 ‘-‘ 则血量-- ,‘+‘ 则血量++ ,若血量cur < 0 则从头再来且初始血量 +1 直至通关,求最后一共走过多少格 .

解: 求前缀和 ,记 ‘-‘ 为 -1 ,‘+‘ 为 +1 ,因为前缀和是连续的 ,所以每次记录血量为 0 时找前缀和第一次为 -1 的下标 ,记录血量为 1 是第一次为 -2 的下标... 最后下标值相加即可 .

#include <bits/stdc++.h>
#define LL long long
#define Pi acos(-1.0)
#define INF 2147483646
#define eps 1e-9
#define MS 1000009
#define mss 17
using namespace std;
// Notice the data size

LL n,m,k;
LL p[MS],a[MS];
char s[MS];

int main() {
	std::ios::sync_with_stdio(false);
	cin >> k;
	while(k--){
		cin >> s;
		LL h = strlen(s);
		LL t = 0 ,cc = -1 ,tot = 0;
		for(int i=0;i<h;i++){
			if(s[i] == ‘-‘){
				p[i+1] = p[i] - 1;
			}
			else p[i+1] = p[i] + 1;
			if(p[i+1] == cc){
				cc--;
				a[++tot] = i+1; // 记录值为-1 ,-2 ,-3 ...的下标
			}
		}
		LL ans = 0; // 记录答案
		for(int i=1;i<=tot;i++){
			ans += a[i];
		}
		ans += h; // 加上通关的一遍
		printf("%lld
",ans);
	}
	
	
	return 0;
}

D. Maximum Sum on Even Positions

You are given an array a consisting of n integers. Indices of the array start from zero (i.?e. the first element is a0, the second one is a1, and so on).

You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of a with borders l and r is a[l;r]=al,al+1,…,ar.

Your task is to reverse such a subarray that the sum of elements on even positions of the resulting array is maximized (i.?e. the sum of elements a0,a2,…,a2k for integer k=?n?12? should be maximum possible).

You have to answer t independent test cases.

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

The first line of the test case contains one integer n (1≤n≤2?105) — the length of a. The second line of the test case contains n integers a0,a1,…,an?1 (1≤ai≤109), where ai is the i-th element of a.

It is guaranteed that the sum of n does not exceed 2?105 (∑n≤2?105).

Output
For each test case, print the answer on the separate line — the maximum possible sum of elements on even positions after reversing at most one subarray (continuous subsegment) of a.

Example

input

4
8
1 7 3 4 7 6 2 9
5
1 2 1 2 1
10
7 8 4 5 7 6 8 9 7 3
4
3 1 2 1

output

26
5
37
5

题意: 给一段数组 ,可以翻转一次连续的子序列 ,使得 a0 ,a2 ,a4 ... ,a2k 之和最大 ,输出最大值 .

解: 显然翻转长度为奇数的序列没有任何用处 ,所以翻转偶数长度的片段 .

例如 7 8 4 5 7 6 本来是 7 + 4 + 7 翻转后为 8 + 5 + 6,也就是相当于 7 8 换位 ,4 5 换位 ,7 6 换位

则 记录两两换位后的差值存储与数组 a ,原数组 p 是 7 8 4 5 7 6 则 a 为 1 1 -1 ,显然此时交换 7 8 4 5 比交换整体更赚 ,所以求数组 a 的连续一段 和最大 的区间值 ta 即可 ,可记录 a 的前缀和求解 .

当然在 7 8 4 5 7 6 中 ,8 不仅可以和 7 交换 ,也可与 4 交换 ,则新建数组 b 记录 8 4 差值 ,5 7 差值 ... 也求数组 b 的连续一段 和最大 的区间值 tb ,取 ta ,tb 大者 .

#include <bits/stdc++.h>
#define LL long long
#define Pi acos(-1.0)
#define INF 2147483646
#define eps 1e-9
#define MS 200009
#define mss 17
using namespace std;
// Notice the data size

LL n,m,k;
LL p[MS],a[MS],b[MS];

int main() {
	std::ios::sync_with_stdio(false);
	cin >> k;
	while(k--){
		a[0] = b[0] = 0;
		LL h,ans = 0;
		cin >> h;
		for(int i=0;i<h;i++){
			cin >> p[i];
			if(!(i&1)) ans += p[i]; // 记录不进行任何翻转操作的答案
		}
		LL maxx = 0,tot = 0;
		for(int i=1;i<h;i+=2){
			a[tot] = p[i] - p[i-1]; // a 差值
			b[tot] = p[i] - p[i+1]; // b 差值
			if(i == h-1) b[tot] = -INF;
			tot++;
		}
		maxx = max(maxx,max(a[0],b[0]));
		LL ta = a[0];
		LL tb = b[0];
		for(int i=1;i<tot;i++){ // 求前缀和
			a[i] += a[i-1]; 
			b[i] += b[i-1];
		}
		for(int i=1;i<tot;i++){ // 求连续一段 和最大 的区间值 maxx
			 ta = min(ta,a[i]);
			 tb = min(tb,b[i]);
			 a[i] = max(a[i],a[i]-ta);
			 b[i] = max(b[i],b[i]-tb);
			 maxx = max(maxx,max(a[i],b[i]));
		}
		 
		printf("%lld
",ans+maxx);
	}
	
	
	return 0;
}










































以上是关于Educational Codeforces Round 90的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27