凉肝的比赛

A - Mezo Playing Zoma

  • 题目描述

Today, Mezo is playing a game. Zoma, a character in that game, is initially at position x=0. Mezo starts sending n commands to Zoma. There are two possible commands:
‘L’ (Left) sets the position x:=x−1;
‘R’ (Right) sets the position x:=x+1.
Unfortunately, Mezo’s controller malfunctions sometimes. Some commands are sent successfully and some are ignored. If the command is ignored then the position x doesn’t change and Mezo simply proceeds to the next command.
For example, if Mezo sends commands “LRLR”, then here are some possible outcomes (underlined commands are sent successfully):
“LRLR” — Zoma moves to the left, to the right, to the left again and to the right for the final time, ending up at position 0;
“LRLR” — Zoma recieves no commands, doesn’t move at all and ends up at position 0 as well;
“LRLR” — Zoma moves to the left, then to the left again and ends up in position −2.
Mezo doesn’t know which commands will be sent successfully beforehand. Thus, he wants to know how many different positions may Zoma end up at.

  • 输入

The first line contains n (1≤n≤105) — the number of commands Mezo sends.
The second line contains a string s of n commands, each either ‘L’ (Left) or ‘R’ (Right).

  • 输出

Print one integer — the number of different positions Zoma may end up at.

  • 样例输入

4
LRLR

  • 样例输出

5

  • 提示

In the example, Zoma may end up anywhere between −2 and 2.

  • 题意

L加一,R减一,但也有可能命令无法执行,求所有可能结果数量。

  • 解题思路

记录数据的范围,L加1,R减1,分别记录0的左区间和右区间,然后加上0。

  • 代码
#include<iostream>
#include<cstdio>

using namespace std;

string s;
int n;
int a,b;

int main() {
	cin >> n;
	cin >> s;
	for(int i = 0;i < n;i++) {
		if(s[i] == 'L') {
			a++;
		} 
		else {
			b--;
		}
	}
	cout << a - b + 1 << endl;
}

B - Just Eat It!

  • 题目描述

Today, Yasser and Adel are at the shop buying cupcakes. There are n cupcake types, arranged from 1 to n on the shelf, and there are infinitely many of each type. The tastiness of a cupcake of type i is an integer ai. There are both tasty and nasty cupcakes, so the tastiness can be positive, zero or negative.
Yasser, of course, wants to try them all, so he will buy exactly one cupcake of each type.
On the other hand, Adel will choose some segment [l,r] (1≤l≤r≤n) that does not include all of cupcakes (he can’t choose [l,r]=[1,n]) and buy exactly one cupcake of each of types l,l+1,…,r.
After that they will compare the total tastiness of the cupcakes each of them have bought. Yasser will be happy if the total tastiness of cupcakes he buys is strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel’s choice.
For example, let the tastinesses of the cupcakes be [7,4,−1]. Yasser will buy all of them, the total tastiness will be 7+4−1=10. Adel can choose segments [7],[4],[−1],[7,4] or [4,−1], their total tastinesses are 7,4,−1,11 and 3, respectively. Adel can choose segment with tastiness 11, and as 10 is not strictly greater than 11, Yasser won’t be happy 😦
Find out if Yasser will be happy after visiting the shop.

  • 输入

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains n (2≤n≤105).
The second line of each test case contains n integers a1,a2,…,an (−109≤ai≤109), where ai represents the tastiness of the i-th type of cupcake.
It is guaranteed that the sum of n over all test cases doesn’t exceed 105.

  • 输出

For each test case, print “YES”, if the total tastiness of cupcakes Yasser buys will always be strictly greater than the total tastiness of cupcakes Adel buys regardless of Adel’s choice. Otherwise, print “NO”.

  • 样例输入

3
4
1 2 3 4
3
7 4 -1
3
5 -5 5

  • 样例输出

YES
NO
NO

  • 提示

In the example, Zoma may end up anywhere between −2 and 2.

  • 题意

Yass会把所有蛋糕吃一次,然后得到蛋糕美味值和恶心值的和,如果有一个子区间>=这个和输出NO。

  • 解题思路

先求出总和,然后开始分两种情况,1-n - 1,还有n。
1.1 - n - 1:求出每一个前缀的最小区间和然后相减,存一个最大值。
2.n:因为n如果减第一个数就是总区间,所以需要特判一下。

  • 代码
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

const int maxn = 2e5 + 10;

long long a[maxn];
long long sum1,sum2;
long long minx;
long long ans;
int t,n;

int main() {
	cin >> t;
	while(t--) {
		sum1 = 0;
		sum2 = 0;
		minx = 0;
		cin >> n;
		for(int i = 0;i < n;i++) {
			scanf("%lld", &a[i]);
			sum1 += a[i];
		}
		ans = a[0];
		for(int i = 0;i < n - 1;i++) {
			sum2 += a[i];
			ans = max(ans,sum2 - minx);
			ans = max(ans,sum1 - sum2);
			minx = min(sum2,minx);
		}
		if(ans < sum1) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

C - Fadi and LCM

  • 题目描述

Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a,b) such that LCM(a,b) equals X. Both a and b should be positive integers.
LCM(a,b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6,8)=24, LCM(4,12)=12, LCM(2,3)=6.
Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?

  • 输入

The first and only line contains an integer X (1≤X≤1012).

  • 输出

Print two positive integers, a and b, such that the value of max(a,b) is minimum possible and LCM(a,b) equals X. If there are several possible such pairs, you can print any.

  • 样例输入

2
6
4
1

  • 样例输出

1 2
2 3
1 4
1 1

  • 提示

  • 题意

LCM(a,b)是两个数的最小公倍数,max(a,b)同时要最小。

  • 提示

  • 解题思路

本题主要需要知道两个数的乘积除以两个数的最大公约数就是最小公倍数这个公式,a * b / gcd(a,b) == LCM(a,b)。用一个minx记录最小值,穷举X的所有约数,特判一下类似于4这种情况不允许两个数相等即可。

  • 代码
#include<iostream>
#include<cstdio>

using namespace std;

long long x;
long long a,b;
long long ans;
long long minx;

long long gcd(long long a,long long b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	minx = 1e12 + 10;
	cin >> x;
	for(long long i = 2;i <= x / i;i++) {
		if(x % i == 0) {
			if(x / (gcd(i,x / i)) == x) {
				if(minx > x / i) {
					minx = x / i;
					ans++;
				}
			}
		}
	}
	if(ans == 0) {
		printf("1 %lld", x);
	}
	else {
		printf("%lld %lld",x / minx,minx);
	}
	return 0;
}

E - Deadline

  • 题目描述

Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results.
Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days optimizing the program, he will make the program run in ⌈dx+1⌉ days (⌈a⌉ is the ceiling function: ⌈2.4⌉=3, ⌈2⌉=2). The program cannot be run and optimized simultaneously, so the total number of days he will spend is equal to x+⌈dx+1⌉.
Will Adilbek be able to provide the generated results in no more than n days?

  • 输入

The first line contains a single integer T (1≤T≤50) — the number of test cases.
The next T lines contain test cases – one per line. Each line contains two integers n and d (1≤n≤109, 1≤d≤109) — the number of days before the deadline and the number of days the program runs.

  • 输出

Print T answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in n days or NO (case insensitive) otherwise.

  • 样例输入

3
1 1
4 5
5 11

  • 样例输出

YES
YES
NO

  • 提示

In the first test case, Adilbek decides not to optimize the program at all, since d≤n.
In the second test case, Adilbek can spend 1 day optimizing the program and it will run ⌈52⌉=3 days. In total, he will spend 4 days and will fit in the limit.
In the third test case, it’s impossible to fit in the limit. For example, if Adilbek will optimize the program 2 days, it’ll still work ⌈112+1⌉=4 days.

  • 题意

给你n天时间完成一个需要d天运行完的程序,你可以花时间将程序优化到d/(x + 1),但优化和运行无法同时进行,请问是否可以在n天内完成这个程序。

  • 解题思路

这题我没推导公式,直接找规律的,当时比赛前一天晚上刚打的codeforces,这题当时做出来被hack了,训练赛比赛前俩小时刚补的,当时没开long long,int被爆了。这题我把它分成了三种情况
1.d <= n这就直接输出YES就行
2.偶数情况下d <= (n / 2) * (n / 2 + 1)输出YES
3.奇数情况下d <= (n / 2 + 1) * (n / 2 + 1)输出YES

  • 代码
#include<iostream>
#include<cstdio>
 
using namespace std;
 
long long n,d;
int t;
 
int main() {
	cin >> t;
	while(t--) {
		scanf("%d %d", &n,&d);
		if(n == 1) {
			if(d > 1) {
				printf("NO\n");
			}
			else {
				printf("YES\n");
			}
		}
		else if(n % 2 == 0) {
			if(d <= (n / 2) * (n / 2 + 1)) {
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
		else if(n % 2 != 0) {
			if(d <= (n / 2 + 1) * (n / 2 + 1)) {
				printf("YES\n");
			}
			else {
				printf("NO\n");
			}
		}
	}
	return 0;
}

F - Yet Another Meme Problem

  • 题目描述

You are given two integers A and B, calculate the number of pairs (a,b) such that 1≤a≤A, 1≤b≤B, and the equation a⋅b+a+b=conc(a,b) is true; conc(a,b) is the concatenation of a and b (for example, conc(12,23)=1223, conc(100,11)=10011). a and b should not contain leading zeroes.

  • 输入

The first line contains t (1≤t≤100) — the number of test cases.
Each test case contains two integers A and B (1≤A,B≤109).

  • 输出

Print one integer — the number of pairs (a,b) such that 1≤a≤A, 1≤b≤B, and the equation a⋅b+a+b=conc(a,b) is true.

  • 样例输入

3
1 11
4 2
191 31415926

  • 样例输出

1
0
1337

  • 题意

求a和b各自区间内,有多少个满足a⋅b+a+b=conc(a,b)规律的数。

  • 解题思路

这题比赛前一天晚上就卡了我,可能是俄罗斯的网站那个提示规律的图片我打不开。。公式又推不出来。。后来在b站看了qscqesze的codeforces讲解,才知道这种找规律的题目可以打表,自己也打表看了一下,就是a * (b最多能有多少个9),这题我也写了个暴力求解的代码,但那个超时太严重了,样例卡了10min才出来1337。。

  • 代码
#include<iostream>
#include<cstdio>

using namespace std;

long long a,b;
long long n;
long long temp;
long long sum;
long long c;
int t;

int main() {
	cin >> t;
	while(t--) {
		c = 0;
		sum = 0;
		temp = 9;
		scanf("%lld %lld", &a,&b);
		if(b < 9) {
			cout << 0 << endl;
			continue;
		}
		while(sum <= b) {
			c++;
			sum += temp;
			temp *= 10;
		}
		c--;
		cout << c * a << endl;
	}
	return 0;
}

G - HQ9+

莫名其妙的一道题目。。反正+号不能输出东西。。开始WA了一下仔细看了下题面,感觉+有问题,就改了下就过了。。

#include<iostream>
#include<cstdio>
 
using namespace std;
 
string s;
int flag;
 
int main() {
	cin >> s;
	flag = 0;
	for(int i = 0;i < s.length();i++) {
		if(s[i] == 'H') {
			flag = 0;
			cout << "YES" << endl;
			break;
		}
		else if(s[i] == 'Q') {
			flag = 0;
			cout << "YES" << endl;
			break;
		}
		else if(s[i] == '9') {
			flag = 0;
			cout << "YES" << endl;
			break;
		}
		else {
			flag = 1;
		}
	}
	if(flag == 1) {
		cout << "NO" << endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值