zoukankan      html  css  js  c++  java
  • Codeforces Round #493题解

    A题

    签到模拟

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pll;
    const int inf=0x3f3f3f3f;
    const int N=1e5+10;
    const int mod=1e9+7;
    int a[N];
    int main(){
        ios::sync_with_stdio(false);
        int n;
        cin>>n;
        int i;
        for(i=1;i<=n;i++){
            cin>>a[i];
        }
        if(n==1){
            cout<<"-1"<<endl;
        }
        else if(n==2){
            if(a[1]==a[2]){
                cout<<-1<<endl;
            }
            else{
                cout<<1<<endl;
                cout<<1<<endl;
            }
        }
        else{
            int mx=0x3f3f3f3f;
            cout<<1<<endl;
            int id;
            for(i=1;i<=n;i++){
                if(mx>a[i]){
                    mx=a[i];
                    id=i;
                }
            }
            cout<<id<<endl;
     
        }
        return 0;
    }
    View Code

    B题

    按奇数偶数分,然后排序贪心求解

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pll;
    const int inf=0x3f3f3f3f;
    const int N=1e5+10;
    const int mod=1e9+7;
    vector<int> num;
    int a[N];
    int main(){
        ios::sync_with_stdio(false);
        int n,b;
        cin>>n>>b;
        int i;
        int cnt1=0;
        int cnt2=0;
        for(i=1;i<=n;i++)
            cin>>a[i];
        for(i=1;i<=n;i++){
            if(a[i]%2){
                cnt1++;
            }
            else{
                cnt2++;
            }
            if(cnt1==cnt2){
                if(i+1<=n){
                    num.push_back(abs(a[i+1]-a[i]));
                }
            }
        }
        sort(num.begin(),num.end());
        int ans=0;
        int cnt=0;
        while(b){
            if(cnt==(int)num.size())
                break;
            if(b-num[cnt]<0)
                break;
            ans++;
            b-=num[cnt];
            cnt++;
        }
        cout<<ans<<endl;
        return 0;
    }
    View Code

    C题

    我们发现每次反转都会少了全0子串,所以贪心判断即可

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pll;
    const int inf=0x3f3f3f3f;
    const int N=1e5+10;
    const int mod=1e9+7;
    int main(){
        ios::sync_with_stdio(false);
        int n,x,y;
        cin>>n>>x>>y;
        string s;
        cin>>s;
        int i;
        if(x>y){
            ll ans=0;
            for(i=0;i<(int)s.size();i++){
                if(s[i]=='0'){
                    ans+=y;
                    while(i<(int)s.size()-1&&s[i+1]=='0')
                        i++;
                }
            }
            cout<<ans<<endl;
        }
        else{
            ll ans=y;
            int cnt=0;
            for(i=0;i<(int)s.size();i++){
                if(s[i]=='0'){
                    cnt++;
                    while(i<(int)s.size()-1&&s[i+1]=='0')
                        i++;
                }
            }
            if(cnt==0){
                cout<<0<<endl;
            }
            else
            cout<<ans+(ll)x*(cnt-1)<<endl;
        }
        return 0;
    }
    View Code

    D题

    这种题显然就是找规律,找到前12个后,后面的规律就比较明显了

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=5e5+10;
    int d[]={0,4,10,20,35,56,83,116,155,198,244,292};
    int main(){
        ios::sync_with_stdio(false);
        ll n;
        cin>>n;
        if(n<=11){
            cout<<d[n]<<endl;
        }
        else{
            ll ans=292;
            cout<<ans+(ll)(n-11)*49<<endl;
        }
    }
    View Code
  • 相关阅读:
    数字图像处理的Matlab实现(2)—MATLAB基础
    数字图像处理的Matlab实现(1)—绪论
    统计分析与R软件-chapter2-6
    统计分析与R软件-chapter2-5
    统计分析与R软件-chapter2-3
    题目1143:Primary Arithmetic
    剑指OFFER之翻转单词顺序
    剑指OFFER之把数组排成最小的数
    剑指OFFER之丑数
    最大的两个数
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/14223015.html
Copyright © 2011-2022 走看看