Codeforces Round #834 A-C

时间:2022-11-29 20:56:36


A

void s(){
string a;
cin >> a;

if(a[0] != 'Y' && a[0] != 'e' && a[0] != 's'){
cout << "No\n";return;
}
for(int i = 0; i < a.size() - 1; i++){
if(a[i] != 'Y' && a[i] != 'e' && a[i] != 's'){
cout << "No\n";return;
}
if(a[i] == 'Y' && a[i + 1] != 'e'){
cout << "No\n";return;
}
if(a[i] == 'e' && a[i + 1] != 's'){
cout << "No\n";return;
}
if(a[i] == 's' && a[i + 1] != 'Y'){
cout << "No\n";return;
}
}cout << "YES\n";

}





B

void s(){
int n, sum;
cin >> n >> sum;

int sum1 = 0;
int sum2 = 0, maxone = -1;
vector<int> a(n + 1);
for(int i = 1; i <= n ;i ++) cin >> a[i], sum2 += a[i], maxone = max(maxone, a[i]);

for(int i = 1; i <= maxone;i ++) {
sum1 += i;
}
if(sum1 - sum2 == sum) {
cout << "YES\n";
return;
}

for(int i = maxone + 1; i <= 1700;i ++) {
sum1 += i;
if(sum1 - sum2 == sum) {
cout << "YES\n";
return;
}
}
cout << "NO\n";
}




C

分析case:

Codeforces Round #834  A-C

1.a == b  直接输出0

2.abs(a - b) >= x 可以一步跳到 输出1

3.如果存在中介c,满足abs(a-c)>=x && abs(b-c)>=x,则可以通过2步跳到

4.前面情况都不满足,则直接通过跳边界三步a->l->r->b或者a->r->l->b能到的话就输出3

5.都不满足就输出-1

void s(){
int l, r, x, a, b;
cin >> l >> r >> x >> a >> b;

if(a == b){
cout << "0\n";return;
}

if(abs(a - b) >= x){
cout << "1\n";return;
}

if( (abs(a - l) >= x && abs(b - l) >= x) || (abs(a - r) >= x && abs(b - r) >= x)){
cout << "2\n";return;
}
if((l<=a-x && r-l >= x && r - b >= x) || (a + x <= r && r - l >= x && b - l >= x)){
cout << "3\n";return;
}

cout << "-1\n";
}