视频讲解Codeforces Round 887 (Div. 2)(A--C)

视频讲解Codeforces Round 887 (Div. 2)(A–C)
在这里插入图片描述

A. Desorting

1、板书

在这里插入图片描述

2、代码

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n;
	cin >> n;
	vector<int>a(n);
	for(int i = 0; i < n; i ++)
		cin >> a[i];
	int ans = INF;
	for(int i = 0; i < n - 1; i ++)
	{
		ans = min(ans, a[i + 1] - a[i]);
	}
	if(ans < 0)
	{
		cout << 0 << endl;
		return;
	}
	cout << ans / 2 + 1 << endl;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();
}

B. Fibonaccharsis

1、板书

在这里插入图片描述

2、代码

#include<bits/stdc++.h>
#define int long long 
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n,k;
	cin >> n >> k;
	if(k > 30)
	{
		cout << 0 << endl;
		return;
	}
	int ans = 0;
	for(int i = n / 2; i <= n; i ++)
	{
		int flag = true;
		vector<int>a(k);
		a[k - 1] = n, a[k - 2] = i;
		for(int j = k - 3; j >= 0; j --)
		{
			a[j] = a[j + 2] - a[j + 1]; 
		}
		for(int j = 0; j < k - 1; j ++)
		{
			if(a[j] < 0 || a[j] > a[j + 1])
			{
				flag = false;
				break;
			}
		}
		if(flag)
			ans ++;

	}
	cout << ans << endl;

}

// void test()
// {
// 	int a1 = 0, a2 = 1;
// 	int a3 = 0;
// 	int cnt = 2;
// 	for(int i = 0; a3 < 2e5; i ++)
// 	{
// 		a3 = a1 + a2;
// 		cnt ++;
// 		a1 = a2, a2 = a3;
// 	}
// 	cout << cnt << endl;
// }

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();

}

C. Ntarsis’ Set

1、板书

在这里插入图片描述

2、代码

#include<bits/stdc++.h>
#define endl '\n'
#define int long long 
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;
int n, k;

bool check(int mid, vector<int>&a)
{
	for(int i = 0; i < k; i ++)
	{
		int p = upper_bound(a.begin(), a.end(), mid) - a.begin();
		mid -= p;
		if(mid <= 0)
			return false;
	}
	return true;
}

void solve()
{
	cin >> n >> k;
	vector<int>a(n);
	for(int i = 0; i < n; i ++)
		cin >> a[i];
	int l = 1, r = 1e18;
	while(l < r)
	{
		int mid = l + r >> 1;
		if(check(mid, a))
			r = mid;
		else
			l = mid + 1;
	}
	cout << l << endl;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,根据提供的引用内容,我无法理解你具体想要问什么问题。请提供更清晰明确的问题,我将竭诚为你解答。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [【CodeforcesCodeforces Round 865 (Div. 2) (补赛)](https://blog.csdn.net/t_mod/article/details/130104033)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值