Educational Codeforces Round 159 (Rated for Div. 2)

Problem - A - Codeforces

// Problem: A. Binary Imbalance
// Contest: Codeforces - Educational Codeforces Round 159 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1902/problem/A
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include//切割strtream头文件
#include//INT_MAX文件
#include 
#include//for unique_ptr shared_ptr
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA(x) cout << x << endl;
#define lowbit(x) x & -x
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int n, m, k, d, T = 1, A, B;

templatevoid read(T &x) {
    T f = 1;x = 0;char s = getchar();
    while(s < '0' || s > '9') {if(s == '-')f = -1;s = getchar();}
    while(s >= '0' && s <= '9') {x = x * 10 + s - '0';s = getchar();}
    x *= f;
}

templatevoid print(T x) {
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
    putchar('\n');
}
constexpr int Init(int x)
{
	return x * 2;
}
void solve()
{
	auto x = make_unique();
	string s;
	cin >> n >> s;
	int num1 = 0,num2 = 0;
	for(auto &x : s)x == '1' ? num1 += 1 : num2 += 1;
	if(num2 > num1)cout << "YES" << endl;
	else
	cout << (num2 >= 1? "YES" : "NO") << endl;
}
 
signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}
题解:
情况无非为
1: 0满足条件 == YES
2: 0不满足条件 == >> 0存在 ? "YES" : "NO"

 

Problem - B - Codeforces 

// Problem: B. Getting Points
// Contest: Codeforces - Educational Codeforces Round 159 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1902/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include//切割strtream头文件
#include//INT_MAX文件
#include 
#include//for unique_ptr shared_ptr
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA(x) cout << x << endl;
#define lowbit(x) x & -x
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int n, m, k, d, T = 1, A, B;

templatevoid read(T &x) {
    T f = 1;x = 0;char s = getchar();
    while(s < '0' || s > '9') {if(s == '-')f = -1;s = getchar();}
    while(s >= '0' && s <= '9') {x = x * 10 + s - '0';s = getchar();}
    x *= f;
}

templatevoid print(T x) {
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
    putchar('\n');
}
constexpr int Init(int x)
{
	return x * 2;
}

int fun(int sc, int lsc)
{
	if(sc <= lsc)return 1;
	return sc / lsc + (sc / lsc * lsc != sc);
}
int min(int a,int b)
{
	return a > b ? a : b;
}
void solve()
{
	auto x = make_unique();
	int n, P, l, t;
	cin >> n >> P >> l >> t;  // les  task
	//one day one lesson and two task
	int k = (n - 1) / 7 + 1;//周数 
	int r = (k * t) + (k / 2 + 1) * l;
	int day = 0;
	if(P > r) day = k / 2 + 1 + fun(P - r, l);
	else day = fun(P, 2 * t + l);
	cout << n - day << endl;
}
 
signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
   	cin >> T;
    while (T--) solve();
    return 0;
}
题解:
贪心:
一天最大化收益为2任务 + 1课程
即每2周存在一天可以实现该情况
== >> 计算最大化收益的方式可以获取多少学分
== >> 最大化收益的方式获得的学分 > 所需学分 == >> day = 所需学分 / 每日最大化收益学分
== >> 反之 day = 可最大化收益方式的天数 + 剩下所需学分 / 课程可修学分
== >> ans = n - day

 Problem - C - Codeforces

// Problem: C. Insert and Equalize
// Contest: Codeforces - Educational Codeforces Round 159 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1902/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include//切割strtream头文件
#include//INT_MAX文件
#include 
#include//for unique_ptr shared_ptr
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA(x) cout << x << endl;
#define lowbit(x) x & -x
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int n, m, k, d, T = 1, A, B;

templatevoid read(T &x) {
    T f = 1;x = 0;char s = getchar();
    while(s < '0' || s > '9') {if(s == '-')f = -1;s = getchar();}
    while(s >= '0' && s <= '9') {x = x * 10 + s - '0';s = getchar();}
    x *= f;
}

templatevoid print(T x) {
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
    putchar('\n');
}

constexpr int Init(int x)
{
	return x * 2;
}
int a[maxn];

void solve()
{
	//求最小的ans,在已知的数组a中的最大和最小时,a[n + 1]越小,ans 越小(最差的情况为max_element(a + 1,a + 1 + n) + g)
	map M;
	cin >> n;
	for(int i = 1;i <= n;i++)cin >> a[i],M[a[i]] = 1;
	if(n == 1){cout << 1 << endl;return;}
	int *mx = max_element(a + 1,a + 1 + n);
	int g = a[2] - a[1], ans = 0;
	for(int i = 2;i <= n;i++)g = __gcd(g,a[i] - a[i - 1]);//求gcd 保证能满足题意要求
	g = g > 0 ? g : -g;
	for(int i = 1;i <= n;i++)ans += (*mx - a[i]) / g;//求1 - n位置的操作次数
	for(int i = 1;i <= n;i++)
	{
		if(!M[*mx - g * i])
		{
			ans += i;
			break;
		}
	}
	cout << ans << endl;
}
 
signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

 

题解:
代码中包含讲解。

你可能感兴趣的:(cf,算法)