Codeforces #690 (Div. 3) 解题报告

Codeforces #690 Div. 3 ABCD 解题报告


手痒补了一下水题,来发一篇题解!

A. Favorite Sequence

在这里插入图片描述
题解:
给出一串数字,按要求重新排序
【左边第一个】 【右边第一个】 【左边第二个】 【右边第二个】 … 以此类推。
解法:双指针,判断条件是i < j
但是如果总长度是奇数的话,那么最后还要输出 a[n / 2 + 1] 这个数字。

详情请看代码: 👇👇👇👇

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<algorithm>
 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define MOD 1e9 + 7
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';ch = getchar(); }
	return s * w;
}
//最大公约数
int gcd(int x,int y) {
    if(x<y) swap(x,y);//很多人会遗忘,大数在前小数在后
    //递归终止条件千万不要漏了,辗转相除法
    return x % y ? gcd(y, x % y) : y;
}
//计算x和y的最小公倍数
int lcm(int x,int y) {
    return x * y / gcd(x, y);//使用公式
}
int ksm(int a, int b, int mod) { int s = 1; while(b) {if(b&1) s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 310;
int a[N];
signed main(){
	int t = read();
	while (t--) {
		int n = read();
		for (int i = 1; i <= n; ++i) {
			a[i] = read();
		}
		
		
		for (int i = 1, j = n; i < j; ++i, --j) {
			printf("%lld ", a[i]);
			printf("%lld ", a[j]);
		}
		if (n % 2) printf("%lld", a[n / 2 + 1]);
		printf("\n");
	}
	return 0;
}

B.Last Year’s Substring

在这里插入图片描述
在这里插入图片描述
题解:
给定一个字符串,判断该字符串是否满足,只消掉任意一段字串,就可以得到 “2020” 这个字符串。只能操作一次。所以总共只有5种情况是YES

  1. 2020 …
  2. 202 … 0
  3. 20 … 20
  4. 2 … 020
  5. … 2020
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define MOD 1e9 + 7
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';ch = getchar(); }
	return s * w;
}
//最大公约数
int gcd(int x,int y) {
    if(x<y) swap(x,y);//很多人会遗忘,大数在前小数在后
    //递归终止条件千万不要漏了,辗转相除法
    return x % y ? gcd(y, x % y) : y;
}
//计算x和y的最小公倍数
int lcm(int x,int y) {
    return x * y / gcd(x, y);//使用公式
}
int ksm(int a, int b, int mod) { int s = 1; while(b) {if(b&1) s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 210;
char a[N];
signed main() 
{
	int t = read();
	while (t--) {
		int n = read();
		for (int i = 1; i <= n; ++i) {
			scanf("%c", &a[i]);
		}
		
		if (a[1] == '2' && a[2] == '0' && a[3] == '2' && a[4] == '0') printf("YES\n");
		else if (a[1] == '2' && a[2] == '0' && a[3] == '2' && a[n] == '0') printf("YES\n");
		else if (a[1] == '2' && a[2] == '0' && a[n - 1] == '2' && a[n] == '0') printf("YES\n");
		else if (a[1] == '2' && a[n - 2] == '0' && a[n - 1] == '2' && a[n] == '0') printf("YES\n");
		else if (a[n - 3] == '2' && a[n - 2] == '0' && a[n - 1] == '2' && a[n] == '0') printf("YES\n");
		else printf("NO\n");
	}
	
	return 0;
}

C. Unique Number

在这里插入图片描述
题意:给定一个正数x,求最小的正整数,且所有数字的和等于x,并且所有数字都不相同(唯一)。
题解:从右往左,能取最大就取最大。注意:超过45就不可以了,因为 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define MOD 1e9 + 7
using namespace std;
int read()
{
	int w = 1, s = 0;
	char ch = getchar();
	while (ch < '0' || ch>'9') { if (ch == '-') w = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0';ch = getchar(); }
	return s * w;
}
//最大公约数
int gcd(int x,int y) {
    if(x<y) swap(x,y);//很多人会遗忘,大数在前小数在后
    //递归终止条件千万不要漏了,辗转相除法
    return x % y ? gcd(y, x % y) : y;
}
//计算x和y的最小公倍数
int lcm(int x,int y) {
    return x * y / gcd(x, y);//使用公式
}
int ksm(int a, int b, int mod) { int s = 1; while(b) {if(b&1) s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 210;
char a[N];
signed main() 
{
	int t = read();
	while (t--) {
		int n = read();
		if (n > 45) {
			printf("-1\n");
			continue;
		}
		
		if (n <= 9) printf("%lld\n", n);
		else if (n > 9 && n <= 17) printf("%lld9\n", n - 9);
		else if (n > 17 && n <= 24) printf("%lld89\n", n - 17);
		else if (n > 24 && n <= 30) printf("%lld789\n", n - 24);
		else if (n > 30 && n <= 35) printf("%lld6789\n", n - 30);
		else if (n > 35 && n <= 39) printf("%lld56789\n", n - 35);
		else if (n > 39 && n <= 42) printf("%lld456789\n", n - 39);
		else if (n > 42 && n <= 44) printf("%lld3456789\n", n - 42);
		else printf("123456789\n");
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值