csust-8..5早训CF之800-1600分

目录

 

A - Meeting of Old Friends

B - Filya and Homework

C - Sonya and Queries

D - Crazy Computer

E - Complete the Word

F - Plus and Square Root


A - Meeting of Old Friends

 CodeForces - 714A 

题目链接https://codeforces.com/problemset/problem/714/A

#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
const int inf = 1e8 + 10;
#define ll long long
int main()
{
	ll a, b, c, d, k;
	cin >> a >> b >> c >> d >> k;
	if (a > c) swap(a, c);
	if (b > d) swap(b, d);
	ll ans = 0;
	if (b - c < 0) cout << "0" << '\n';
	else {
		ans = b - c + 1;
		if (k >= c && k <= b) ans--;
		cout << ans << endl;;
	}
	return 0;
}

B - Filya and Homework

 CodeForces - 714B 

题目链接https://codeforces.com/problemset/problem/714/B

#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
const int inf = 1e8 + 10;
#define ll long long
int a[mac];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a + 1, a + 1 + n);
	if (a[1] == a[n]) {
		printf("YES\n");
		return 0;
	} 
	else {
		int p = -1, nb = 0, a1 = -1, a2 = -1, a3 = -1;
		for (int i = 1; i <= n; i++) {
			if (a[i] != p) {
				nb++, p = a[i];
				if (a1 < 0) a1 = a[i];
				else if (a2 < 0) a2 = a[i];
				else a3 = a[i];
			}
		}
		if (nb > 3) printf("NO\n");
		else {
			if(nb < 3 ||(nb == 3 && a3 - a2 == a2 - a1))
				cout << "YES" ;
			else {
				cout << "NO";
			}
		}
	}
	return 0;
}

C - Sonya and Queries

 CodeForces - 714C 

题目链接https://codeforces.com/problemset/problem/714/C

#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
char s[50], ss[10];
int vis[1 << 20];
int main()
{
	int n;
	scanf("%d", &n);
	while (n--) {
		scanf("%s%s", ss, s);
		if (ss[0] == '+') {
			int len = strlen(s);
			int sum = 0;
			for (int i = 0; i < len; i++) {
				if (s[i] & 1)  sum = sum << 1 | 1;
				else sum = sum << 1;
			}
			vis[sum]++;
		}
		else if (ss[0] == '-') {
			int len = strlen(s);
			int sum = 0;
			for (int i = 0; i < len; i++) {
				if (s[i] & 1)  sum = sum << 1 | 1;
				else sum = sum << 1;
			}
			vis[sum]--;
		}
		else {
			int len = strlen(s);
			int sum = 0;
			for (int i = 0; i < len; i++) {
				if (s[i] & 1)  sum = sum << 1 | 1;
				else sum = sum << 1;
			}
			printf("%d\n", vis[sum]);
		}
	}
	return 0;
}

D - Crazy Computer

 CodeForces - 716A 

题目链接https://codeforces.com/problemset/problem/716/A

#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
const int inf = 1e8 + 10;
#define ll long long
int a[mac];
int main()
{
	int n,m; 
	scanf("%d%d", &n,&m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	if (n==1) {
		printf ("1\n");
		return 0;
	}
	int ans=1;
	int x=1;
	for (int i=2; i<=n; i++){
		if (a[i]-a[i-1]>m) x=i;
	}
	ans=n-x+1;
	printf ("%d\n",ans);
	return 0;
}

E - Complete the Word

 CodeForces - 716B 

题目链接https://codeforces.com/problemset/problem/716/B

#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
const int inf = 1e8 + 10;
#define ll long long
char s[mac];
int vis[mac];
int main()
{
	scanf("%s", s);
	int len = strlen(s);
	if (len < 26) printf("-1\n");
	else {
		int mark = -1, tail = 0;
		for (int i = 0; i < len; i++) {
			if (mark!=-1) break;
			if (s[i] != '?') {
				vis[s[i] - 'A']++;
				while (vis[s[i] - 'A'] > 1) {
					vis[s[tail] - 'A']--;
					tail++;
				}
			}			
			if (i - tail + 1 == 26 ) mark = tail;
		}
		if (mark == -1) {
			printf("-1\n"); return 0;
		}
		for (int i = 0; i < len; i++) {
			if (i == mark) {
				for (int j = i; j < i + 26; j++) {
					if (s[j] == '?') {
						for (int k = 0; k < 26; k++) {
							if (!vis[k]) {
								printf("%c", 'A' + k);
								vis[k] ++; break;
							}
						}
					}
					else printf("%c", s[j]);
				}
				i += 26;
			}
			if (i >= len) {
				printf("\n"); return 0;
			}
			if (s[i] == '?') printf("A");
			else printf("%c", s[i]);
		}
		printf("\n");
	}
	return 0;
}

F - Plus and Square Root

 CodeForces - 716C 

题目链接https://codeforces.com/problemset/problem/716/C

#include <bits/stdc++.h>
using namespace std;
const int mac = 1e5 + 10;
const int inf = 1e8 + 10;
#define ll long long
char s[mac];
int vis[mac];
int main()
{
	int n;
	ll ans = 0, stp = 0, now = 2, lev = 1;
	scanf("%d", &n);
	for (ll i = 1; i < n + 1; i++) {
		if (i == 1) printf("2\n");
		else {
			ans = i * (i + 1) * (i + 1) - (i - 1);
			printf("%lld\n", ans);
		}
	}
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值