Codeforces Round 887 (Div. 2)

Codeforces Round 887 (Div. 2)

 

A. Desorting

题意:

​ 一个长度为n的序列,可以执行任意次操作,将[1, i] 的数字全部加一,且[i+1, n] 的数字全部减一,问最少执行多少次操作可以让该序列非sorted(sorted 即非严格递增)

Idea:

​ 若已经非sorted则不用操作,否则找到最小的 delt = a[i] - a[i-1] ,答案为 ( d e l t + 2 ) / 2 (delt+2)/2 (delt+2)/2

code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int n, m;

void solve(){
    cin >> n;
    vector<int>a(n);
    for(auto &e : a) cin >> e;

    if(!is_sorted(a.begin(), a.end())){
        cout << "0\n";
        return;
    }

    int mn = LLONG_MAX;
    for(int i = 1;i < n;i++){
        mn = min(mn, a[i] - a[i-1]);
    }

    cout << (mn + 2) / 2 << '\n';
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;
    while(t--)solve();

    return 0;
}

 

B. Fibonaccharsis

题意:

​ 有两个整数n,k。问有多少个长k的类斐波那契数列f,且 f k = n f_k=n fk=n

Idea:

​ 设所求数列的前两个数为x,y,则 f 3 , f 4 , f 5 , f 6 . . . . f_3,f_4,f_5,f_6.... f3,f4,f5,f6.... 分别等于 x + y , x + 2 y , 2 x + 3 y , 3 x + 5 y , . . x+y,x+2y,2x+3y,3x+5y,.. x+y,x+2y,2x+3y,3x+5y,.. ,x,y的系数为斐波那契数列,不过y的系数是从斐波那契数列的第二个1开始。于是 f k = k 1 x + k 2 y f_k=k_1x+k_2y fk=k1x+k2y,可求出 k 1 , k 2 k_1 ,k_2 k1k2后枚举合法的 x , y x,y xy对数,即为答案。还有当 k 2 k_2 k2大于n的时候没有合法解,斐波那契数列大概第30位就大于2e5了,所以k大于30时可以直接输出0

code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int n, k;

int ferbo(int n){
	return (sqrt(5)/5)*(pow((1+sqrt(5))/2,n)-pow((1-sqrt(5))/2,n));
}

void solve(){
    cin >> n >> k;
    if(k >= 50){
        cout << "0\n";
        return;
    }
    int f1 = ferbo(k - 2);
    int f2 = ferbo(k - 1);


    int dx = n / (f1 + f2);

    int ans = 0;
    for(int i = 0;i <= dx;i++){
        if((n - f1*i) % f2 == 0) ans++;
    }

    cout << ans << '\n';
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;
    while(t--)solve();

    return 0;
}

 

C. Ntarsis’ Set

题意:

​ 有一个无限大的从一开始逐次加一的数组s,给出一个长n的数组a,执行k次操作:每次删除此时s中第 a 1 , a 2 , a 3 . . . a n a_1,a_2,a_3...a_n a1,a2,a3...an小的数,问最后s中最小的数时多少

Idea:

​ 首先如果 a 1 ! = 1 a_1!=1 a1!=1最后最小值就是1。

​ 每次删除的第一个数就是上一次删除后出现的最小值(第一次删除除外),所以我们可以找每次要删除的第一个数就可以找到最后剩余的最小值是多少。

​ 若一直进行操作:

  • a = { 1 , 5 , 10 } a=\{1,5,10\} a={1,5,10} 时,每次删除的第一个数分别是 1 、 2 、 3 、 4 、 6 、 8 、 11 、 14... 1、2、3、4、6、8、11、14... 1234681114... 因为 a 2 = 5 a_2=5 a2=5,所以在[1,4]区间的数都会被作为第一个数被删除,即被作为最小值。[5,9]区间中因为 a 2 a_2 a2在此区间删除过数,所以删除的第一个数在此区间每次递增加2,同理在[10, + ∞ +\infty +]区间每次递增加3.

​ 利用上述规律求出第k+1 次被删除的第一个数即可

code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int n, k, a[N];

void solve(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++) cin >> a[i];

    if(a[1] != 1){
        cout << 1 << '\n';
        return;
    }

    int ans = 1;
    int cur = 1;
    while(k--){
        ans += cur;
        while(cur + 1 <= n && ans >= a[cur + 1]){
            cur++;
            ans++;
        }
    }

    cout << ans << '\n';

}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while(t--) solve();

    return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BowTen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值