CF补题:Educational Codeforces Round 151 (Rated for Div. 2)(A,B,C,D)

10 篇文章 0 订阅

1.CF1845A

Problem - A - Codeforces

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<numeric>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int>
void func()
{
	int n, k, x;
	cin >> n >> k >> x;
	if (x != 1)
	{
		cout << "YES\n";
		vector<int>ans(n, 1);
		cout << n << endl;
		for (int i = 0; i < n; i++)
		{
			cout << 1 << " \n"[i == n - 1];
		}
	}
	else
	{
		if (k == 1 || (n & 1) && (k == 2))
		{
			cout << "NO\n";
		}
		else
		{
			cout << "YES\n";
			vector<int>ans;
			while (n - 2 >= 2)//奇数最小为3
			{
				n -= 2;
				ans.push_back(2);
			}
			if (n)ans.push_back(n);
			cout << ans.size() << endl;
			for (int i = 0; i < ans.size(); i++)
			{
				cout << ans[i] << " \n"[i == ans.size() - 1];
			}
		}
	}
}
int main()
{
	cin.tie(0), cout.tie(0)->sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
	{
		func();
	}
	return 0;
}


2.CF1845B

Problem - B - Codeforces

注意:相乘越界!不能用两数相乘<0说明不同象限!

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<numeric>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int>
void func()
{
	int x1, y1, x2, y2, x3, y3;
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
	if (((x1 - x3) <0&& (x1 - x2) > 0 )|| ((x1 - x3) > 0 && (x1 - x2) < 0))
	{
		if (((y1 - y3) > 0 && (y1 - y2) < 0) || ((y1 - y3) < 0 && (y1 - y2) > 0))
		{
			cout << 1 << endl;
		}
		else
		cout << min(abs(y1 - y2), abs(y1 - y3)) + 1 << endl;
	}
	else if((x1>x3 &&x1>x2) || (x1<x3 && x1<x2))
	{
		if ((y1 > y3 && y1 > y2) || (y1 < y2 && y1 < y3))
		{
			cout << min(abs(x1 - x2), abs(x1 - x3)) + min(abs(y1 - y2), abs(y1 - y3)) + 1 << endl;
		}
		else
		cout << min(abs(x1 - x2), abs(x1 - x3)) + 1 << endl;
	}
	else if ((x1 - x3) * (x1 - x2) == 0)
	{
		if ((y1 > y3 && y1 > y2) || (y1 < y2 && y1 < y3))
		cout << min(abs(y1 - y2), abs(y1 - y3))+1 << endl;
		else
		cout << 1 << endl;
	}
	else if ((y1 - y3) * (y1 - y2) == 0 )
	{
		if ((x1 > x3 && x1 > x2) || (x1 < x3 && x1 < x2))
		cout << min(abs(x1 - x2), abs(x1 - x3))+1 << endl;
		else
		cout << 1 << endl;
	}

}
int main()
{
	cin.tie(0), cout.tie(0)->sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
	{
		func();
	}
	return 0;
}


3.CF1845C

Problem - C - Codeforces

注意:

1.所有的li<=ri!   

2.找到l到r之间而在s中找不到子串即是OK的。

3.判断找出l与r中所有子串,若所有子串都在s中则NO,否则则至少存在一个YES。

4.目的是找出一个没有的子串!

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<numeric>
#include<map>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int>
void func()
{
	string s;
	int n;
	string l, r;
	cin >> s >> n >> l >> r;
	map<char, int>vis;
	int index = 0;
	int ans = 0;
	for (int i = 0; i < n; i++)//枚举每一位
	{
		vis.clear();
		while (index < s.size())
		{
			if (s[index] >= l[i] && s[index] <= r[i] && !vis.count(s[index]))
			{
				vis[s[index]] = 1;
			}
			index++;
			if (vis.size() == r[i] - l[i] + 1)
			{
				ans++;
				break;
			}
		}
		if (ans >= n)//每一位都有
		{
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}
int main()
{
	cin.tie(0), cout.tie(0)->sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
	{
		func();
	}
	return 0;
}


4.CF1845D

Problem - D - Codeforces

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<numeric>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int>
void func()
{
	int n;
	cin >> n;
	vector<int>a(n+1);
	ll sum = 0;
	ll ans1 = 0;
	ll k = 0;
	ll dif = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		ans1 = max(ans1, sum);
		if (ans1 - sum > dif)//只有这样才能得到有效k
		{
			dif = ans1 - sum;
			k = ans1;
		}
	}
	cout << k << endl;
}
int main()
{
	cin.tie(0), cout.tie(0)->sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
	{
		func();
	}
	return 0;
}


 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值