首页 > 其他分享 >Codeforces Round 909 (Div. 3)

Codeforces Round 909 (Div. 3)

时间:2023-12-04 19:14:19浏览次数:33  
标签:int 909 Codeforces long while solve ans Div define

Codeforces Round 909 (Div. 3)

A

#include <bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;

int n;
void solve(){
    cin>>n;
    for(int i=1;i<=10;i++){
        if(i&1){
            if(n%3==0) n++;
            else{
                cout<<"First"<<endl;
                return;
            }
        }else{
            if(n%3==1) n--;
            else if(n%3==2) n++;
            else n--;
        }
    }
    cout<<"Second"<<endl;
}

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

B

没想到是这么脑残的暴力,,,写半天。

#include <bits/stdc++.h>
#define int unsigned long long
#define endl '\n';
using namespace std;

const int N = 2e5 + 10;
int n;
unsigned long long pre[N];

void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>pre[i];
        pre[i]+=pre[i-1];
    }
    int ans=0;
    for(int len=1;len<=n/2;len++){
        if(n%len) continue;
        int sum1=0;
        int sum2=0;
        for(int i=len;i<=n;i+=len){
            if(sum1==0) sum1=pre[i]-pre[i-len];
            if(sum2==0) sum2=pre[i]-pre[i-len];
            sum1=max(sum1,pre[i]-pre[i-len]);
            sum2=min(sum2,pre[i]-pre[i-len]);
        }
        ans=max(ans,sum1-sum2);
    }
    cout<<ans<<endl;
}

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

C

很典的贪心。代码写的很丑,写晕了。

#include <bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;

const int N = 2e5 + 10;
int a[N];
int n;

void solve(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    int ans=a[1];
    int sum=max(0ll,a[1]);
    for(int i=2;i<=n;i++){
        if((a[i]&1)^(a[i-1]&1)){
            sum+=a[i];
            ans=max(ans,sum);
            ans=max(ans,a[i]);
            if(sum<=0) sum=0;
        }else{
            if(a[i]>0){
                sum=a[i];
                ans=max(sum,ans);
            }
            else{
                sum=0;
                ans=max(ans,a[i]);
            }
        }
    }
    cout<<ans<<endl;
}

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

D

如果 2的a[i]次方/a[i]2的a[j]次方/a[j] 的话{i,j}就是符合题意的,两边都取对数就是 a[i]-log2(a[i])a[j]-log2(a[j])

(这种用了log2的代码不知道会不会被卡掉)

#include <bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;

const int N = 2e5 + 10;
int a[N];
long double b[N];
int n;

void solve(){
    map<long double,int> path;
    int ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        long double x;
        x=1.0*a[i]-log2(a[i]);
        ans+=path[x];
        path[x]++;
    }
    cout<<ans<<endl;
}

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

E

可以发现如果出现 a[i]<a[i-1] ,那么i之前的所有数都要进行一次操作。所以找最后一个逆序出现的位置就行了。

#include <bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;

const int N = 2e5 + 10;
int a[N];
int n;

void solve(){
    cin>>n;
    deque<int> path;
    int minn=-1;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(minn==-1) minn=a[i];
        minn=min(a[i],minn);
        if(a[i]<a[i-1]) path.push_back(i);
    }
    if(path.empty()){
        cout<<0<<endl;
        return;
    }
    int ans=path.back()-1;
    for(int i=1;i<=ans;i++)
        if(a[i]==minn){
            cout<<-1<<endl;
            return;
        }
    cout<<ans<<endl;
}

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

F

写的时候一直没理解题目,,,其实好像拿一个点出来来回跑就行了,

感觉今天这场的题意都怪怪的

看了下别人的代码好像都是维护两条链的.

大佬代码:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int long long

void solve() {
    int n, q;cin >> n >> q;
    vector<int> list1,list2;
    for(int i=2;i<=n;i++){
        cout<<i-1<<" "<<i<<"\n";
        list1.push_back(i);
    }
    list2.push_back(2);
    for(int i=1;i<=q;i++){
        int x;cin>>x;
        if(list1.size()==x){
            cout<<"-1 -1 -1\n";
            continue;
        }
        if(list1.size()>x){
            vector<int> st;
            while(list1.size()>x){
                st.push_back(list1.back());
                list1.pop_back();
            }
            cout<<st.back()<<" "<<list1.back()<<" "<<list2.back()<<"\n";
            while(!st.empty()){
                list2.push_back(st.back());
                st.pop_back();
            }
        }else{
            vector<int> st;
            while(list1.size()+st.size()<x){
                st.push_back(list2.back());
                list2.pop_back();
            }
            cout<<st.back()<<" "<<list2.back()<<" "<<list1.back()<<"\n";
            while(!st.empty()){
                list1.push_back(st.back());
                st.pop_back();
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int t;cin >> t;
    while (t--) solve();
    return 0;
}

标签:int,909,Codeforces,long,while,solve,ans,Div,define
From: https://www.cnblogs.com/zfxyyy/p/17875707.html

相关文章

  • Codeforces Round 911 (Div. 2)
    CodeforcesRound911(Div.2)A.CoverinWater,,,mc无限水#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'usingnamespacestd;voidsolve(){intn;strings;cin>>n>>s;s=""+s+......
  • Codeforces Round 912 (Div. 2)
    CodeforcesRound912(Div.2)什么位运算专场A.HalloumiBoxes#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'usingnamespacestd;inta[110];intn,k;voidsolve(){cin>>n>>k;for(inti=0;i<n;i++)cin&......
  • Educational Codeforces Round 158 (Rated for Div. 2)
    EducationalCodeforcesRound158(RatedforDiv.2)AEDU的题总是感觉写起来怪怪的#include<bits/stdc++.h>#defineintlonglong#defineendl'\n'usingnamespacestd;inta[101];voidsolve(){intn,x;cin>>n>>x;intans=0;......
  • Codeforces Round 912 (Div. 2)补题B、C、D1
    CodeforcesRound912(Div.2)B.StORageroom思路\(a_i\)=\(M_i\)\(_1\)&\(M_i\)\(_2\)&\(M_i\)\(_3\)&...&\(M_i\)\(_n\)\((i!=j)\)ac代码#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong......
  • CF1901 C Add, Divide and Floor 题解
    LinkCF1901CAdd,DivideandFloorQuestion给定一个长度为\(n\)的序列,每次操作你需要选择一个整数\(x\),并将所有\(a_i\)替换为\(\lfloor\frac{a_i+x}{2}\rfloor\)。求至少多少次操作后能将所有\(a_i\)变相同若最少次数小于等于\(n\),输出操作次数和每次操作所选......
  • Educational Codeforces Round 159 (Rated for Div. 2)
    EducationalCodeforcesRound159(RatedforDiv.2)基本情况A题秒了。B题想出来贪心思想,也想出来怎么找最优解了,但实现极其复杂繁琐,最后以先超时优化后又错误的结果告终。B.GettingPoints明显越后面开始学收益越高。然后写了个简单粗暴的纯模拟,T了。#include<iostrea......
  • CodeForces 1900F Local Deletions
    洛谷传送门CF传送门操作没有什么性质,唯一一个性质是,操作次数不超过\(\logn\)(每次至多保留一半元素)。于是我们可以直接模拟操作。但是肯定不能直接模拟。考虑先对原序列模拟一次,求出经过\(i\)次操作后保留的位置集合\(S_i\)。那么只保留\([l,r]\)的元素,可能会造成端点......
  • Codeforces Round 911 (Div. 2)
    Preface忙里偷闲补一下之前欠下的一些CF这场前5个题都极其一眼,然而F瞪了好久愣是屁都不会感觉现在水平有有点到瓶颈了,以前是Div2D写完卡现在是Div2E写完卡,但至少还是在进步的A.CoverinWater如果存在某个空地块的长度大于\(2\)则可以用两个块造出无限水,否则答案就是所有空......
  • Codeforces Round 881 (Div. 3)
    CodeforcesRound881(Div.3)A:ABCA.SashaandArrayColoring题意:求最大的着色成本(着色成本是指同一个颜色的最大值-最小值)思路:肯定不能是相同的,直接最大-最小就行#include<bits/stdc++.h>usingnamespacestd;inta[60];voidsolve(){intn;cin>>n;......
  • [Codeforces] CF1807E Interview
    题目翻译有\(n\)堆石头,其中\(n-1\)堆都只有重量为一克的石头,剩下一堆有则有一块有两克的石头和若干重量为一克的石头。你的任务是在\(30\)次询问内推理出那一堆有重量为两克的石头是第几堆。首先输入\(n\),接下来输入\(n\)个数\(a_1,a_2\dotsa_n\),其中\(a_i\)表示......