Educational Codeforces Round 99 (Rated for Div. 2)

Educational Codeforces Round 99 (Rated for Div. 2)

A. Strange Functions

输出位数即可

#include <bits/stdc++.h>

#define int long long
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;

void solve() {
    
    
    string s;
    cin>>s;
    cout<<s.size()<<endl;
}

signed main() {
    
    
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--)
        solve();
    return 0;
}

B. Jumps

只有比a[i]小1时无法通过把一个之前加k的操作改为-1来改变,只能加一次操作-1

#include <bits/stdc++.h>

#define int long long
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;

int a[maxn];

void init(){
    
    
    for (int i = 1; i <=maxn; ++i) a[i]+=a[i-1]+i;
}

void solve() {
    
    
    int x;
    cin>>x;
    int res=1;
    while (a[res]<x) res++;
    if(x+1==a[res]) cout<<res+1<<endl;
    else cout<<res<<"\n";
}

signed main() {
    
    
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;init();
    while (_--)
        solve();
    return 0;
}

C. Ping-pong

因为要保证赢得场数多所以开局全不接到你最后一个我才开始接

#include <bits/stdc++.h>

#define int long long
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;

void solve() {
    
    
    int x,y;
    cin>>x>>y;
    cout<<x-1<<" "<<y<<endl;
}

signed main() {
    
    
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--)
        solve();
    return 0;
}

D. Sequence and Swaps

直接换然后每次检查是否顺序即可

#include <bits/stdc++.h>

#define int long long
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;

int a[maxn];
int n,x;
bool check(){
    
    
    for (int i = 1; i <n; ++i)
        if(a[i]>a[i+1]) return 0;
    return 1;
}

void solve() {
    
    
    cin>>n>>x;
    int ans=0;
    for (int i = 1; i <=n; ++i) cin>>a[i];
    for (int i = 1; i <=n; ++i) {
    
    
        if(check()) break;
        if (a[i]>x) swap(x,a[i]),ans++;
    }
    cout<<(check()?ans:-1)<<"\n";
}

signed main() {
    
    
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--)
        solve();
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45436102/article/details/110528590
今日推荐