zoukankan      html  css  js  c++  java
  • Codeforces Round #249 (Div. 2) A B

    C好像就是个模拟。D 是个编码复杂度大的,可是好像也就是枚举三角形,我这会儿准备区域赛,尽量找点思维难度大的,所以昨晚A B 还是去做区域赛题吧.....

    B 也有点意思 贪心

    题意:交换相邻两个位的数。然后最多换k次,求最大数

    解法,找<=k范围内的最大数。与之交换。右移一位。继续找,直到k用完

    //#pragma comment(linker, "/STACK:102400000,102400000")
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <map>
    #include <set>
    #include <queue>
    using namespace std;
    
    #define ls(rt) rt*2
    #define rs(rt) rt*2+1
    #define ll long long
    #define ull unsigned long long
    #define rep(i,s,e) for(int i=s;i<e;i++)
    #define repe(i,s,e) for(int i=s;i<=e;i++)
    #define CL(a,b) memset(a,b,sizeof(a))
    #define IN(s) freopen(s,"r",stdin)
    #define OUT(s) freopen(s,"w",stdout)
    const ll ll_INF = ((ull)(-1))>>1;
    const double EPS = 1e-8;
    const double pi = acos(-1.0);
    const int INF = 100000000;
    
    int num[65];
    ll a;
    int k;
    
    int change()
    {
        ll t=a;
        int f=0;
        while(t)
        {
            num[f++]=t%10;
            t/=10;
        }
        return f;
    }
    
    void print()
    {
        int id=64;
        while(!num[id])--id;
        //printf("%d",num[id]);
        for(int i=id;i>=0;i--)
            printf("%d",num[i]);
        putchar('
    ');
    }
    
    int main()
    {
    
        while(~scanf("%I64d%d",&a,&k))
        {
            CL(num,0);
            int wei=change();
            wei--;
            for(int i=wei;i>=0;i--)
            {
                int maxpos=i,mx=num[i],cnt=k;
                for(int j=i-1;j>=0 && cnt>=1;j--)//
                {
                    cnt--;
                    if(num[j]  > mx){mx=num[j];maxpos=j;}
                }
                //k-=i-maxpos;
                //cout << "***************"  << endl;
                //cout << "mx=" << mx << "pos=" << maxpos << endl;
                //print();
                ///////
               // printf("i=%d k=%d
    ",i,k);
                //for(int j=i-1;j>=maxpos && k>=1;j--)
                    //swap(num[j],num[j+1]),k--;
                for(int j=maxpos;j<=i-1&&k>=1;j++)
                    swap(num[j],num[j+1]),k--;
                if(!k)break;
            }
            print();
        }
        return 0;
    }
    

    A  纯模拟暴力

    //#pragma comment(linker, "/STACK:102400000,102400000")
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <map>
    #include <set>
    #include <queue>
    using namespace std;
    
    #define ls(rt) rt*2
    #define rs(rt) rt*2+1
    #define ll long long
    #define ull unsigned long long
    #define rep(i,s,e) for(int i=s;i<e;i++)
    #define repe(i,s,e) for(int i=s;i<=e;i++)
    #define CL(a,b) memset(a,b,sizeof(a))
    #define IN(s) freopen(s,"r",stdin)
    #define OUT(s) freopen(s,"w",stdout)
    const ll ll_INF = ((ull)(-1))>>1;
    const double EPS = 1e-8;
    const double pi = acos(-1.0);
    const int INF = 100000000;
    
    const int MAXN= 200;
    int num[MAXN];
    
    int main()
    {
        int n,m;
        while(~scanf("%d%d",&n,&m))
        {
            for(int i=0;i<n;i++)
                scanf("%d",&num[i]);
            int ans=0,d=0;
            for(int i=0;i<n;i++)
            {
                if(m-d>=num[i])
                {
                    d+=num[i];
                }
                else
                {
                    ans++;
                    d=num[i];
                }
            }
            printf("%d
    ",ans+1);
        }
        return 0;
    }
    


  • 相关阅读:
    SpringCloudAlibaba
    wechat kill
    使用vscode调试 pomelo
    Terry的学习笔记ASP.NET MVC 4 HELLO WORLD 分析编辑页面添加搜索页面
    Terry的学习笔记ASP.NET MVC 4 HELLO WORLD添加视图(View)
    Terry的学习笔记ASP.NET MVC 4 简介
    正则表达式总结
    自己编写的 objectDataSource 配合 GridView 实现分页
    Terry的学习笔记ASP.NET MVC 4 HELLO WORLD 从控制器访问模型中的数据
    Terry的学习笔记ASP.NET MVC 4 HELLO WORLD添加控制器(Controller)
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5184130.html
Copyright © 2011-2022 走看看