A. Soccer
while Dima was not watching the game, the teams never had an equal score
At any given time, only one team can score a goal, so the score 𝑥 : 𝑦 can change to either (𝑥+1) : 𝑦, or x : (𝑦+1).
#include<iostream>
using namespace std;
void solve(){
int a, b, c, d;
cin >> a >> b >> c >> d;
if(a == b || c == d){
cout << "No" << endl;
return ;
}
if(b > a){
if(d > c)
cout << "Yes" << endl;
else
cout << "No" << endl;
}else{
if(c > d)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
int main(){
int n;
cin >> n;
for(int i = 0; i < n; i ++)
solve();
return 0;
}
B. Collatz Conjecture
Given the initial values of x, y, and k, Maxim wants to know what is the final value of x
There is a variable 𝑥 and a constant 𝑦. The following operation is performed 𝑘 times:
- increase 𝑥 by 1, then
- while the number 𝑥 is divisible by 𝑦, divide it by y.
#include<iostream>
using namespace std;
void solve(){
int a, b, c;
cin >> a >> b >> c ;
int k = b - a % b;
int x = a + k;
c = c - k;
while(c >= 0){
while(x % b == 0)
x = x / b;
if(x == 1)
break;
k = b - x % b;
c = c - k;
x += k;
}
if(x == 1 && c >= 0){
c = c % (b - 1);
}
cout << x + c << endl;
}
int main(){
int n;
cin >> n;
for(int i = 0; i < n; i ++)
solve();
return 0;
}
C. Boring Day
he takes a non-zero number of cards from the top of the deck and finishes the round. If the sum of the numbers on the cards collected during the round is between l𝑙 and r𝑟, inclusive, the round is won; otherwise, it is lost.
Help Egor determine the maximum number of rounds he can win in such a game
#include<bits/stdc++.h>
using namespace std;
int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
x=x*10+ch-'0',ch=getchar();
return x*f;
}
void solve(){
int n, l, r;
n = read();
l = read();
r = read();
int sum = 0;
int res = 0;
int h = 0;
vector<int> a(n);
for(int i = 0; i < n; i ++){
a[i] = read();
sum += a[i];
while(sum > r && h <= i){
sum -= a[h];
h ++;
}
if(sum >= l){
res ++;
sum = 0;
h = i + 1;
}
}
cout << res << endl;
}
int main(){
int n;
cin >> n;
for(int i = 0; i < n; i ++)
solve();
return 0;
}