Educational Codeforces Round 108 (Rated for Div. 2)

又是一场cf爆零的场,明明看的很简单,基本上所有的性质都挖掘出来了,但是都没有严格的推出来(难过

反思:

  1. 基础判断不扎实,分析出来所有性质没有敏感的抓住答案的实现
  2. 题目理解判断失误严重第二题让问到(n, m)的花费是不是k,而不是在(n, m)范围内能不能到k

A Red and Blue Beans

贪心来放,优先把合法的最大的方案放好;如果消耗的最大的那组比原本的多,那么就说明是合法的。因为最后一个没有足够的来放满最大合法方案,那么他也是可以放好的

// Problem: A. Red and Blue Beans
// Contest: Codeforces - Educational Codeforces Round 108 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1519/problem/0
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Code by: ING__
// 
// Powered by CP Editor (https://cpeditor.org)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int T;
int r, b, d;

int main(){
	cin >> T;
	while(T--){
		cin >> r >> b >> d;
		if(r < b){
			swap(r, b);
		}
		if(r <= 1ll * (d + 1) * b){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	re 0;
}




B The Cake Is a Lie

问在到(n, m)的点的花费是不是k;其实我们观察后发现,无论走哪条路,结果都和直来直去一样

所以判断一下就好了

// Problem: B. The Cake Is a Lie
// Contest: Codeforces - Educational Codeforces Round 108 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1519/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Code by: ING__
// 
// Powered by CP Editor (https://cpeditor.org)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int T;
int n, m, k;

int main(){
	cin >> T;
	while(T--){
		cin >> n >> m >> k;
		int maxx = (n - 1) + (m - 1) * n;
		if(maxx == k) cout << "YES" << Endl;
		else cout << "NO" << Endl;
	}
	re 0;
}

C Berland Regional

参考了一下大佬的写法

题意指的是我们要看在不同的分配人员队伍情况下,所有学校的队伍的总能力是多少

最好的办法就是求前缀和来看每个学校的队伍人数是多少

那么每一次确定一个队伍人数k的时候取前缀和 s [ l / k ∗ k ] s[l / k * k] s[l/kk](每组学校能有多少的k队伍,每个队伍有k人,下取整性质保证了不满k的不选)

// Problem: C. Berland Regional
// Contest: Codeforces - Educational Codeforces Round 108 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1519/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Code by: ING__
// 
// Powered by CP Editor (https://cpeditor.org)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"

using namespace std;

typedef pair<int, int> PII;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int T;
// vector<int> v[200000 + 10];
vector<ll> s[200000 + 10];
ll ans[200000 + 10];
int n;

struct nope{
	int u;
	int s;
}a[200000 + 10];

bool cmp(ll a, ll b){
	return a > b;
}

int main(){
	cin >> T;
	while(T--){
		memset(ans, 0, sizeof(ans));
		
		cin >> n;
		for(int i = 1; i <= n; i++){
			scanf("%d", &a[i].u);
			s[i].clear(); // 由于vector数组还有数组的性质,不能直接在外面s.clear()
		}
		
		for(int i = 1; i <= n; i++){
			scanf("%d", &a[i].s);
			s[a[i].u].push_back(a[i].s);
		}
		
		// int maxx = 0;

		
		for(int i = 1; i <= n; i++){
			sort(s[i].begin(), s[i].end(), cmp);
		}
		
		for(int i = 1; i <= n; i++){
			int l = s[i].size();
			for(int j = 1; j < l; j++){
				s[i][j] += s[i][j - 1];	 // 像大佬学习的,在原数组下进行求出前缀和,规避了下标从0开始
			}
		}
		
		for(int i = 1; i <= n; i++){
			int l = s[i].size();
			for(int j = 1; j <= l; j++){
				ans[j] += s[i][l / j * j - 1]; // 因为前缀和下标是从0开始的,所以要减一
			}
		}
		
		for(int i = 1; i <= n; i++){
			cout << ans[i] << " ";
		}
		cout << endl;
	}
	re 0;
}

D Maximum Sum of Products

(代补

区间DP

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值