CF补题:CodeTON Round 5 (Div. 1 + Div. 2, Rated, Prizes!)(B,C)

10 篇文章 0 订阅

1.CF1842B

Problem - B - Codeforces

注意:只能一个一个拿,前面的不拿后面也拿不了(后面都不要了)

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<numeric>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int>
void func()
{
	int n, x;
	cin >> n >> x;
	int y = 0;
	for (int i = 0; i < 3; i++)
	{
		bool k = 1;
		for (int j = 0; j < n; j++)
		{
			int tt;
			cin >> tt;
			if ((x | tt) != x)//若头个不能得到,则k=0,后面的都不要了
				k = 0;
			if(k==1)
				y |= tt;
		}
	}
	if (y == x)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main()
{
	cin.tie(0), cout.tie(0)->sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
	{
		func();
	}
	return 0;
}


2.CF1842C

Problem - C - Codeforces

思路:value[i]表示数字为i的前面(不包括自己)的数的数目,初始为正无穷。

f[i]表示走到第i个数的所留下来的数的数目,答案为总的减去留下来的即是移走的。

重点:f[i]=min(f[i-1]+1,value[a[i]])--->若遇到相同数字,f左移。

value[a[i]]=min(f[i-1],value[a[i]])--->若遇到相同数字,去掉两个相同数字中间的数字,左移。

注意:a数组所包含的数在1到n之间。

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<numeric>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int>
const int N = 2e5 + 100;
void func()
{
	int n;
	cin >> n;
	vector<int>a(n+1,0);
	vector<int>value(n+1,0);
	vector<int>f(n+1,0);
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		value[i] = 0x3f3f3f3f;
	}
	for (int i = 1; i <= n; i++)
	{
		f[i] = min(f[i - 1] + 1, value[a[i]]);
		value[a[i]] = min(f[i - 1], value[a[i]]);
	}
	cout << n - f[n] << endl;
}
int main()
{
	cin.tie(0), cout.tie(0)->sync_with_stdio(false);
	int t;
	cin >> t;
	while (t--)
	{
		func();
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值