CF补题:Educational Codeforces Round 151 (Rated for Div. 2)(A,B,C,D)
1.CF1845A
#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
注意:相乘越界!不能用两数相乘<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
注意:
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
#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;
}