Codeforces Round #803 (Div. 2)(A,B,C)

比赛链接

A. XOR Mixup

 题意:给你一个长度为n序列,看是否其中n - 1个元素的异或值是否等于剩下的一个

 思路:

        1.数据很小可以暴力

        2.一个数异或同一个数两次等于他自己本身

AC代码

#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<cmath> 
#include<cstdio>
#include<vector> 
#include<stack>
#include<queue>
#include<algorithm>
#include<list>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
#define inf 0x3f3f3f3f
#define endl "\n"
typedef long long ll;
using namespace std;
int t,n,m,k;
string s;

void solve()
{
	cin >> t;
	while(t--){
		cin >> n;
		vector <int> v(n);
		int rs = 0;
		for(auto & x : v){
			cin >> x;
			rs ^= x;
		} 
		for(int i = 0 ; i < n ; i ++){
			if(rs ^ v[i] == v[i]){
				cout << v[i] << endl;
				break;
			}
		}
	}
}
int main() {
	IOS;                           
	solve();     
	return 0; 
}



B. Rising Sand

 题意:给你一个长度为n的序列,你可以选择一个长度为k的区间,使得其中每个都加上1,最后问最多有多少个顶峰(ai > ai-1 + ai+1)

思路:

情况1:

 假如他不满足顶峰,让中间k个区间都加上一,然而并不会改变他们的相对大小,式子始终不成立

情况2:当K==1时,说明每次加一可以改变他们的相对大小,就可以改成3,2,2,2...的形式

 

最终的个数为 (N - 1) / 2 个。

AC代码:

#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<cmath> 
#include<cstdio>
#include<vector> 
#include<stack>
#include<queue>
#include<algorithm>
#include<list>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
#define inf 0x3f3f3f3f
#define endl "\n"
typedef long long ll;
using namespace std;
int t,n,m,k;
string s;

void solve()
{
	cin >> t;
	while(t--){
		cin >> n >> k;
		vector <int> v(n);
		int ans = 0;
		for(auto & x : v) cin >> x;
		for(int i = 1 ; i < n - 1 ; i++){
			if(v[i] > v[i - 1] + v[i + 1]){
				ans++;
			}
		}
		if(k == 1) cout << (n - 1) / 2 << endl;
		else cout << ans << endl;
	}
}
int main() {
	IOS;                           
	solve();     
	return 0; 
}

C. 3SUM Closure

题意:给你一个序列,判断是否序列满足 ai + aj + ak = al ,其中al是否在序列中。

思路:从数据的范围贪心判断即可,这个题只需要判断四个数就能过

AC代码

#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<cmath> 
#include<cstdio>
#include<vector> 
#include<stack>
#include<queue>
#include<algorithm>
#include<list>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PII pair<int,int>
#define inf 0x3f3f3f3f
#define endl "\n"
typedef long long ll;
using namespace std;
int t,n,m,k;
string s;

void solve()
{
	cin >> t;
	while(t--){
		cin >> n;
		vector <ll> v(n);
		map <ll,ll> mp; 
		for(auto & x : v){
			cin >> x;
			mp[x] = 1; 
		}
		sort(v.begin(),v.end());
	
		if(!mp[v[0] + v[1] + v[2]] || !mp[v[n -1] + v[n - 2] + v[n - 3]] || !mp[v[0] + v[1] + v[n - 1]] || !mp[v[0] + v[n-1] + v[n -2] ])  cout <<  "NO" << endl;
		else cout << "YES" << endl;
	}
}
int main() {
	IOS;                           
	solve();     
	return 0; 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值