首页 > 其他分享 >Codeforces Round 887(Div 2)(A-C)

Codeforces Round 887(Div 2)(A-C)

时间:2023-07-24 20:35:31浏览次数:40  
标签:887 int Codeforces long cin -- while using Div

A. Desorting

题目里说的无序是指后面的一个数大于前面一个数,所以只要有一个 a[i+1]-a[i]<0 就说明已经符合题目的无序要求了,不需要改变即可,即输出0
如果有该序列是非严格递增的根据题目所说的改变就只需要求出最小的差值即可,最后用最小的差值除以2(因为每次可以让选中的部分之前的加一,之后的减一,每次改变的差值为2)再加一

代码如下:

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int>a(n);
        int diff=1e9;
        bool fg=true;
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<n-1;i++)
        {
            if(a[i+1]-a[i]<0)fg=false;
            diff=min(diff,a[i+1]-a[i]);
        }
        if(fg==false)cout<<0<<endl;
        else cout<<diff/2+1<<endl;
    }
    return 0;
}

B. Fibonaccharsis

标准代码说实话我没大看懂

#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int T; cin >> T;
    
    while (T--) {
 
        int n; int k;
        cin >> n >> k;
     
        int ans = 0;
     
        for (int i = 1; i <= n; i++) {
            int second = n; //xth element where x is k
            int first = i; //fixing x-1th element where x is k-1
            bool valid_seq = true;
            for (int j = 0; j < k - 2; j++) {
                //for s_x and s_x-1, s_x-2 = s_x - s_x-1
                int fx = first;
                first = second - fx;
                second = fx;
                valid_seq &= first <= second;
                valid_seq &= min(first, second) >= 0;
                if (!valid_seq) break; //break if the sequence is not fibonacci-like
            }
            if (valid_seq) ans++;
        }
 
        cout << ans << endl;
    }
 
}

C. Ntarsis' Set

假设这些数字按递增的顺序排列在一条直线上。在某一天之前看看每个数字x。如果这一天他没有被删除,那么他就占据了什么新的位置,他之前的位置对他有什么影响
答: 如果 x位于a[i]和a[i+1]之间,他将移动到x-i的新位置,因为在它之前的i个位置已经被删除
利用这一观察结果,反向模拟这一过程,我们就可以得到答案

#include<bits/stdc++.h>

using namespace std;
using LL = long long;

const int N = 2e5 + 5;

LL a[N];

inline void solve() {
    LL n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    LL j = 0, ans = 1;
    while (k--) {
        while (j < n && a[j] <= ans + j) j++;
        ans += j;
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int T;
    cin >> T;
    while (T--) solve();
}

标签:887,int,Codeforces,long,cin,--,while,using,Div
From: https://www.cnblogs.com/OhLonesomeMe/p/17578263.html

相关文章

  • 【题解】Imbalanced Arrays - Codeforces 1852B
    出处:CodeforcesRound887链接:https://codeforces.com/problemset/problem/1852/B题目大意:给定一个包含\(n\)个非负整数的频次序列\(f\)。构造任意一个等长的整数序列\(b\),要求①\(b\in[-n,n]\)but$b\neq0$②\(b\)中不存在相反数③对于每个坐标\(i\)......
  • Codeforces Round 886 (Div. 4)
    Dashboard-CodeforcesRound886(Div.4)-CodeforcesA.ToMyCritics判断任意两个大于10即可#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintN=2e5+10;signedmain(){ios::sync_with_stdio(false);cin.tie(nullptr);......
  • 【题解】Ntarsis' Set - Codeforces 1852A
    出处:CodeforcesRound887链接:https://codeforces.com/problemset/problem/1852/A题目大意:给定一个包含\(n\)个正整数的表示删除位置的严格升序序列\(p\),以及另外一个连续正整数的被删除的无穷序列\(l\)。进行\(k\)次删除操作,每次操作从无穷序列\(l\)中同时删除位......
  • Educational Codeforces Round 71
    A.ThereAreTwoTypesOfBurgers#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve(){intb,p,f,h,c;cin>>b>>p>>f>>h>>c;b/=2;intres=0;for(inti......
  • Codeforces Round 887 (Div. 1) 题解
    https://codeforces.com/contest/1852/problemsA.Ntarsis'Sethttps://codeforces.com/contest/1852/problem/A感觉不是很一眼。\(n\)和\(k\)都是\(2\times10^5\),不能暴力,设当前集合为\({1,2,\dots,10^{1000}}\),那么被操作过一次的最小值就应该是\(\text{MEX}(0,......
  • CodeForces 1810G The Maximum Prefix
    洛谷传送门CF传送门感觉是比较educational的题。拿到题目应该有一个大致思路,就是考虑最大前缀和的求法,再把它扔到状态里面。最大前缀和有两种求法:从前往后求,需要维护当前前缀和\(s\),当前最大前缀和\(mx\),需要记录两个变量,无法承受。从后往前求,只需记录当前最大前缀和......
  • 「题解」Codeforces Round 887 (Div. 2)
    A.DesortingProblem题目Sol&Code若序列一开始无序答案为\(0\)若有序即\(a_1\leqa_2\leq\dots\leqa_n\)。若想让\(a_i>a_j(i<j)\),操作次数与两数差值\(d(d=a_j-a_i)\)相关为\(\lfloor\dfrac{d}{2}\rfloor+1\),差值越小操作次数越少,故枚举相邻两数取最少......
  • Codeforces Round 887 (Div. 2)
    C.Ntarsis'Set​ (\(1\leqn,k\leq2\cdot10^5\))题解:思维+二分我们不妨反向考虑由于答案最后一次一定在第一个位置所以答案上一轮一定在第一个空的位置,假设这个位置为\(x\)那么如果说要使得答案在位置\(x\),那么上上一轮答案一定在第\(x\)个空的位置我们可以......
  • Codeforces Round 887 (Div 2) C. Ntarsis' Set
    Ntarsis'Set题意是给你n个数,每次按照顺序删除位于a[i]位置的这n个数,问k次后最小的是多少参考这位大佬的题解CodeforcesRound887(Div2)A~C-知乎(zhihu.com)结合一个官方题解,进行一次操作后,由于前面删掉i个数,a[i]到a[i+1]间所有数的排名都要-=i,那么在a[i]到a[i+1]之间的......
  • 【题解】Educational Codeforces Round 151(CF1845)
    VP战报:1h过了A,B,C,D然后被E罚坐1hrank:210th题解只有A-EA.ForbiddenInteger题目描述:你需要构造一个正整数序列,满足:对于\(i\),\(a_i\lek\)且\(a_i\not=x\)。\(\suma_i=n\)。如无法构造,输出NO,否则输出YES后,输出序列长度与序列中的每一个数。多测\(t\le......