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<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
#include<memory>//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;

template<typename T>void 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;
}

template<typename T>void 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<int>();
	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<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
#include<memory>//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;

template<typename T>void 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;
}

template<typename T>void 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>();
	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<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
#include<memory>//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;

template<typename T>void 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;
}

template<typename T>void 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<int,int> 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;
}

 

题解:
代码中包含讲解。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值