当前位置:网站首页>Codeforces Round #803 (Div. 2)(A-D)
Codeforces Round #803 (Div. 2)(A-D)
2022-07-04 08:38:00 【ccsu_ yuyuzi】
Dashboard - Codeforces Round #803 (Div. 2) - Codeforceshttps://codeforces.com/contest/1698
A. XOR Mixup
The question :n A digital , Guarantee n-1 Numbers after XOR are the same as the remaining numbers , Find that number .
Ideas : Two identical numbers are XOR followed by 0, Then the question becomes n The number XOR equals 0 了 , Then we can output an input number randomly .
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
#define int long long
using namespace std;
void solve()
{
int n,x;
int ans=0;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&x);
printf("%lld\n",x);
return;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}
B. Rising Sand
Problem - B - Codeforceshttps://codeforces.com/contest/1698/problem/B
The question : In the long for 1 To n In the array , When 2 To (n-1) An element appears a[i]>a[i-1]+a[i+1], Result contribution +1. We can operate a length of k Subarray of a continuous array of , Every subarray element should +1, Ask what is the biggest contribution to the results .
Ideas : When k>1 when , Because successive cities +1, According to the above inequality , At least both sides should be at the same time +1, Therefore, no matter how many operations are performed, the result contribution will not be increased . In this case, you can directly traverse the result . When k be equal to 1 when , Just output the results greedily .
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
using namespace std;
int arr[200005];
void solve()
{
int n,k,cnt=0;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%d",&arr[i]);
if(k==1)
{
printf("%d\n",(n-1)/2);
}
else
{
for(int i=2;i<=n-1;i++)
if(arr[i]>arr[i-1]+arr[i+1])
cnt++;
printf("%d\n",cnt);
}
return;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}
C. 3SUM Closure
Problem - C - Codeforceshttps://codeforces.com/contest/1698/problem/C The question : Give you an array , Ask whether to make all a[i]+a[j]+a[k]=a[l],a[l] Is an element in an array , And i<j<k.
Ideas : This problem has a rule , When the array contains 0 And it must be true when there is only one non-zero number , If there are two non-zero numbers, make sure that the sum of the two is equal to 0. however , It should be noted that , When the array length is small , There are many special situations to deal with , such as [ 1,-1,2 ] etc. , It's too troublesome to consider , Just let the array be short and perform violent simulation .
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
using namespace std;
void solve()
{
int n,x,cnt=0,x1=0,x2=0;
scanf("%d",&n);
if(n<=10)
{
int a[11];
map<int,int>ma;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]),ma[a[i]]=1;
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
for(int k=j+1;k<=n;k++)
{
int ans=a[i]+a[j]+a[k];
if(ma[ans]==0)
{
printf("NO\n");
return ;
}
}
}
}
printf("YES\n");
return;
}
// Array length is short , Direct violence
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
if (x!=0)
{
cnt++;
if(x1==0)
x1=x;
else if(x2==0)
x2=x;
}
}
if((cnt==2||cnt==0)&&x1+x2==0)
printf("YES\n");
else if(cnt==1)
printf("YES\n");
else
printf("NO\n");
// law
return;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}
D. Fixed Point Guessing
Problem - D - Codeforceshttps://codeforces.com/contest/1698/problem/D I haven't written interactive questions before , But this interaction is really simple .
Direct bisection interval , When the number of elements in the input interval in the bisection interval is even , It indicates that the exchange has taken place in the interval , Then the result is in the other half , Continue to score two points .
#include<map>
#include<cmath>
#include<set>
#include<queue>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_set>
#include<unordered_map>
using namespace std;
bool check(int l,int r)
{
cout<<"? "<<l<<" "<<r<<endl;
int cnt=0,x;
for(int i=l;i<=r;i++)
{
cin>>x;
if(l<=x&&x<=r)
cnt++;
}
if(cnt%2)
return true;
else
return false;
}
void solve()
{
int n;
scanf("%d",&n);
int l=1,r=n;
while(l<r)
{
int mid=(l+r)>>1;
if(check(l,mid))
r=mid;
else
l=mid+1;
}
cout<<"! "<<r<<endl;
return ;
}
signed main()
{
int t;
cin>>t;
while(t--)
solve();
return 0;
}
Pay attention to fflush(stdout) or cout.flush() in C++; Or directly <<endl.
边栏推荐
- manjaro安装微信
- DM8 uses different databases to archive and recover after multiple failures
- Use preg_ Match extracts the string into the array between: & | people PHP
- Group programming ladder race - exercise set l2-002 linked list de duplication
- How to get bytes containing null terminators from a string- c#
- Openfeign service interface call
- ctfshow web255 web 256 web257
- C # implements a queue in which everything can be sorted
- System disk expansion in virtual machine
- string. Format without decimal places will generate unexpected rounding - C #
猜你喜欢
1、卡尔曼滤波-最佳的线性滤波器
Sports [running 01] a programmer's half horse challenge: preparation before running + adjustment during running + recovery after running (experience sharing)
yolov5 xml数据集转换为VOC数据集
Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources
What if I forget the router password
Getting started with microservices: gateway gateway
How college students choose suitable computers
Moher college phpMyAdmin background file contains analysis traceability
NewH3C——ACL
Fault analysis | MySQL: unique key constraint failure
随机推荐
Moher college phpMyAdmin background file contains analysis traceability
Four essential material websites for we media people to help you easily create popular models
微服務入門:Gateway網關
Li Kou today's question -1200 Minimum absolute difference
SSRF vulnerability exploitation - attack redis
Démarrage des microservices: passerelle
How college students choose suitable computers
Codeforces Global Round 21(A-E)
A method for detecting outliers of data
Snipaste convenient screenshot software, which can be copied on the screen
没有Kubernetes怎么玩Dapr?
4 small ways to make your Tiktok video clearer
PHP converts seconds to timestamps - PHP
团体程序设计天梯赛-练习集 L2-002 链表去重
[BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
【无标题】转发最小二乘法
[go basics] 2 - go basic sentences
Leetcode 23. Merge K ascending linked lists
Unity text superscript square representation +text judge whether the text is empty
Const string inside function - C #