Codeforces Round 961 (Div. 2)(A~D)

A - Diagonals

题意

在这里插入图片描述

思路

贪心,先将占有单元格最多的对角线填满,然后依次往下填。直接暴力或者二分都行。

代码

// Problem: A. Diagonals
// Contest: Codeforces - Codeforces Round 961 (Div. 2)
// URL: https://codeforces.com/contest/1995/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){
   
   
	return b > 0 ? gcd(b , a % b) : a;
}

LL lcm(LL a , LL b){
   
   
	return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){
   
   
	for(int i = 0 ; i <= n ; i ++){
   
   
		a[i] = 0;
	}
}
void solve() 
{
   
   
	int n , k;
	cin >> n >> k;
	int ans = 0;
	if(k >= n){
   
   
		ans++;
		k -= n;
	}	
	n -= 1;
	while(n > 0 && k > 0){
   
   
		if(k >= 2 * n){
   
   
			k -= 2 * n;
			ans += 2;
		}
		else{
   
   
			ans += (k - 1) / n + 1;
			k = 0;
		}
		n--;
	}
	cout << ans << endl;
}            
int main() 
{
   
   
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    int t=1;
	cin>>t;
    while(t--)
    {
   
   
    	solve();
    }
    return 0;
}

B2 - Bouquet (Hard Version)

题意

给定

思路

根据题意,最多可以选择两种不同的花购买。若只选一种花,那么就用这 m m m个金币买尽可能多的花即可。若选了两种花,我们可以先用这 m m m枚金币买尽可能多的价格少的那一种花,然后再用剩下的钱买尽可能多的价格多的那一种花。那么接下来,要么花全部买完了,要么剩下的钱不足以买下任意一朵花。
然后,我们可以通过放弃价格少的一种花,再购买价格多的那一种花,使得所得到的花瓣加 1 1 1。每次执行这一个操作可以使得花瓣加 1 1 1,接下来我们只需要求最多可以执行多少次这样的操作即可,然后便可以求出最大的花瓣数。

代码

// Problem: B2. Bouquet (Hard Version)
// Contest: Codeforces - Codeforces Round 961 (Div. 2)
// URL: https://codeforces.com/contest/1995/problem/B2
// Memory Limit: 256 MB
// Time Limit: 1500 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
#define int l
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值