当前位置:网站首页>Codeworks round 651 (Div. 2) ABCD solution
Codeworks round 651 (Div. 2) ABCD solution
2022-07-25 00:32:00 【Think-killer】
A. Maximum GCD Topic link
Divide 2 that will do
#include<iostream>
using namespace std;
int main()
{
int n;
int t;
scanf("%d",&t);
while(t--){
cin>>n;
cout<<n/2<<endl;
}
return 0;
}
B. GCD Compression Topic link
Answer key : We can pair odd numbers and even numbers separately , In this way, the sum of each pair of numbers can be 2 to be divisible by . Please note that , We can always form n−1 Yes , Because in the worst case , We will discard an odd number and an even number . If we discard multiple even or odd numbers , We can form another pair with an even sum .
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n;
int a[N];
int main()
{
int t;
cin >> t;
while(t--)
{
cin >> n;
vector< int > even, odd;
for(int i = 1; i <= 2 * n; i++)
{
cin >> a[i];
if(a[i] % 2)
odd.push_back(i);
else
even.push_back(i);
}
vector< pair< int, int > > ans;
for(int i = 0; i + 1 < odd.size(); i += 2)
ans.push_back({
odd[i], odd[i + 1]});
for(int i = 0; i + 1 < even.size(); i += 2)
ans.push_back({
even[i], even[i + 1]});
for(int i = 0; i < n - 1; i++)
cout << ans[i].first << " " << ans[i].second << endl;
}
return 0;
}
C. Number Game Topic link
The question : Give you a number n, You can do two things , Divide by any greater than 1 The latter is in n Greater than 1 Subtract 1,Ashishgup Go ahead , Until I can't go , If Ashishgup I can't go , be FastestFinger win .
Answer key :FastestFinger stay n=1,n=2 Of x Power ,n Is even and n/2 Greater than or equal to 3 Win in three cases
#include<bits/stdc++.h>
using namespace std;
bool isprime(int x){
if(x<3)return 0;
for(int i=2;i<=sqrt(x);i++)
if(x%i==0)
return 0;
return 1;
}
bool check(int x){
for(int i=2;i<31;i++)if(pow(2,i)==x)return 1;
return 0;
}
int main(){
int t,n;cin>>t;
while(t--){
cin>>n;
if(n==1||check(n)||(n%2==0&&isprime(n/2)))
cout<<"FastestFinger\n";
else
cout<<"Ashishgup\n";
}
}
D. Odd-Even Subsequence Topic link
Answer key :
Binary search for answers , And check whether it is given x, At least a subsequence of length can be formed .k Make all elements in the odd index or even index ≤x.
#include < bits/stdc++.h >
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N = 2e5 + 5;
int n, k;
int a[N];
bool check(int x, int cur)
{
int ans = 0;
for(int i = 1; i <= n; i++)
{
if(!cur)
{
ans++;
cur ^= 1;
}
else
{
if(a[i] <= x)
{
ans++;
cur ^= 1;
}
}
}
return ans >= k;
}
int binsearch(int lo, int hi)
{
while(lo < hi)
{
int mid = (lo + hi) / 2;
if(check(mid, 0) || check(mid, 1))
hi = mid;
else
lo = mid + 1;
}
return lo;
}
int32_t main()
{
IOS;
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
int ans = binsearch(1, 1e9);
cout << ans;
return 0;
}
边栏推荐
- What can testers do when there is an online bug?
- @Mapkey usage instructions
- QT project - security monitoring system (function realization of each interface)
- Server intranet and Extranet
- Palm package manager of kubernetes learning offline installation of NFS client provider
- Fast development board for Godson solid state drive startup (burning system to solid state) - partition
- BGP machine room and BGP
- Why does [mindspore ascend] [custom operator] repeatedly assign values to one tensor affect another tensor?
- Detailed explanation of alexnet of paddlepaddle paper series (with source code)
- [leetcode weekly replay] 303rd weekly 20220724
猜你喜欢

WPF implements RichTextBox keyword query highlighting

Improve static loading dynamic loading

Financial RPA robot enables enterprises to open a new era of intelligence

Quartus: install cyclone 10 LP device library for quartus version 17.1

Automated test series selenium three kinds of waiting for detailed explanation

Qt学习-利用数据库单例完成 登录匹配 + 注册 功能实现

Moonpdflib Preview PDF usage record

2. Load test

Notes on topic brushing (XXII) -- Dynamic Planning: basic ideas and topics

1. Smoke test
随机推荐
Nodejs package
If real-time intersection with line segments in online CAD drawings is realized
[Bert] transformer/bert/attention interview questions and answers
R language plot visualization: plot to visualize the residual analysis diagram of the regression model, the scatter diagram of the predicted value and residual corresponding to the training set and th
Notes on topic brushing (XXII) -- Dynamic Planning: basic ideas and topics
线段树杂谈
C language force buckle the flipped number of question 7. Violence Act
Docker container Django + MySQL service
Deep and direct visual slam
Install K6 test tool
Heavy forecast! Analysys, together with Microsoft and the Central University of Finance and economics, talks about the digital economy
[help] mindspire training based on ascend910 cannot reproduce the model effect on GPU
2022 Henan Mengxin League game 2: Henan University of technology K - Rice
Daily question 1 · 1260. Two dimensional network migration · simulation
Implement a avatar looping control
LeetCode_ 6124_ The first letter that appears twice
Weekly summary (*66): next five years
[英雄星球七月集训LeetCode解题日报] 第24日 线段树
自动化测试系列-Selenium三种等待详解
Install software on kubernetes cluster using helm 3 package manager