当前位置:网站首页>【Codeforces Round #808 (Div 2.) A·B·C】
【Codeforces Round #808 (Div 2.) A·B·C】
2022-07-27 00:35:00 【Romantic dog】
Better reading experience \color{red}{ Better reading experience } Better reading experience
Catalog
A. Difference Operations
Original link
thought
- if a i ( i > = 2 ) a_i(i>=2) ai(i>=2) Can pass a i = a i − a i − 1 a_i=a_i-a_{i-1} ai=ai−ai−1 Turn into 0 0 0
- explain : a i − 1 ∣ a i a_{i-1}|a_i ai−1∣ai
- if a i − 1 ( i > = 2 ) a_{i-1}(i>=2) ai−1(i>=2) Can pass a i − 1 = a i − 1 − a i − 2 a_{i-1}=a_{i-1}-a_{i-2} ai−1=ai−1−ai−2 Turn into 0 0 0
- explain : a i 2 ∣ a i − 1 a_{i_2}|a_{i-1} ai2∣ai−1
- It can be obtained. , When a i ( i > = 2 ) a_i(i>=2) ai(i>=2) It can be 0 0 0 when
- explain : a 1 ∣ a i a_1|a_i a1∣ai
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
int a[N];
void solve(){
int n;
cin >> n;
for(int i = 1 ; i <= n ; i++){
cin >> a[i];
}
bool flag = 1;
int t = a[1];
for(int i = 2 ; i <= n ; i++){
if(a[i] % t != 0){
flag = 0;
break;
}
}
if(flag) cout << "YES" << "\n";
else cout << "NO" << "\n";
}
int main(){
int tt;
cin >> tt;
while(tt -- ){
solve();
}
return 0;
}
B. Difference of GCDs
Original link
thought
- requirement g c d ( i , a i ) gcd(i,a_i) gcd(i,ai) In the sequence formed , g c d ( i , a i ) gcd(i,a_i) gcd(i,ai) All different
- explain g c d ( i , a i ) = i gcd(i,a_i)=i gcd(i,ai)=i, namely i ∣ a i i|a_i i∣ai
- So it needs to be in the interval [ l , r ] [l,r] [l,r] Search for i i i Multiple
- about a i a_i ai, if l ⩽ a i = ⌊ r i ⌋ × i ⩽ r l\leqslant a_i=\lfloor \frac{r}{i}\rfloor\times i\leqslant r l⩽ai=⌊ir⌋×i⩽r, Then the conditions are met
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
int a[N];
void solve(){
int n, l, r;
cin >> n >> l >> r;
bool flag = 1;
for(int i = 1; i <= n; i++){
a[i] = r / i * i;
if(a[i] < l ){
flag = 0;
break;
}
}
if(flag){
cout << "YES" << "\n";
for(int i = 1; i <= n; i++) cout << a[i] << " ";
cout << "\n";
}
else cout << "NO" << "\n";
}
int main(){
int tt;
cin >> tt;
while(tt--){
solve();
}
return 0;
}
C. Doremy’s IQ
Original link
thought
- Reverse greed
- Consider from the last day , Set the upper limit of IQ to Q Q Q, The IQ on the last day is q i = 0 q_i=0 qi=0
- if a i ⩽ q i a_i \leqslant q_i ai⩽qi, Is the first i i i Day's game needs to be played
- if a i > q i a_i \gt q_i ai>qi, And q i < Q q_i<Q qi<Q when , Ruodi i i i Day fight , be q i = q i + 1 q_i=q_i+1 qi=qi+1
- because a i > q i a_i>q_i ai>qi I played the most games Q Q Q Time , For the previous games, we should continue to play , need q i q_i qi As big as possible
- so a i > q i a_i \gt q_i ai>qi, And q i < Q q_i<Q qi<Q when , This section i i i Days of competition must be played , q i = q i + 1 q_i=q_i+1 qi=qi+1
- if a i > q i a_i>q_i ai>qi, And q i = Q q_i=Q qi=Q when , The first i i i Days of competition cannot be played
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
int a[N];
void solve(){
int n,m;
cin >> n >> m;
string s(n,'0');
for(int i = 0; i < n; i++) cin >> a[i];
int q=0;
for(int i = n-1; i >= 0; i--){
if(a[i] <= q) s[i] = '1';
else if(a[i] > q && q < m){
q++;
s[i] = '1';
}
}
cout << s << "\n";
}
int main(){
int tt;
cin >> tt;
while(tt--){
solve();
}
return 0;
}
Postscript
- I was a little nervous during the competition this day
- A A A and B B B They are all types of mathematical proof , It's troublesome to think , Get yourself trapped
- After the game, I found that A A A and B B B It's so simple , Or my math foundation is not good , Suffer a great loss QAQ
- C C C Question one eye
DP, Greed was considered during the game , But it didn't prove , I don't know how to deal with the problem of reverse greed - I hope it will turn green soon ......( I'm so stupid )
边栏推荐
猜你喜欢

6_梯度下降法(Gradient Descent)

13_集成学习和随机森林(Ensemble Learning and Random Forests)

Leetcode - hash table

RecBole使用1

CDs simulation of minimum dominating set based on MATLAB

13_ Ensemble learning and random forests

The crawler parses the object of the web page. Element name method

Drawing warehouse Tsai

Viterbi Viterbi decoding bit error rate simulation, modulation is QPSK, channel is Gaussian white noise

c语言 static运用,灵活改变生命周期,让你写代码如鱼得水
随机推荐
10_ Evaluate classification
Find method of web page parsing by crawler
Signal and system impulse response and step response
Friend友元函数以及单例模式
Machine learning model -- lightgbm
TypeScript(tsconfig.json)
Deep learning of parameter adjustment skills
八皇后 N皇后
Web middleware log analysis script 2.0 (shell script)
Uni app learning (II)
Blue Bridge Cup 1004 [recursive] cow story
8_多项式回归及模型泛化(Polynomial Regression and Model Generalization)
Today's 20220719 toss deeplobcut
Alexnet (pytoch Implementation)
[LeetCode] 无重复最长字符串
CCPD data set processing (target detection and text recognition)
deeplabcut使用1
【 Educational Codeforces Round 132 (Rated for Div. 2) A·B·C】
A simple prime number program. Beginners hope that older bosses can have a look
Eight queens n Queens