zoukankan      html  css  js  c++  java
  • 国庆5

    Codeforces 1060 b

    You are given a positive integer nn.

    Let S(x)S(x) be sum of digits in base 10 representation of xx, for example, S(123)=1+2+3=6S(123)=1+2+3=6, S(0)=0S(0)=0.

    Your task is to find two integers a,ba,b, such that 0a,bn0≤a,b≤n, a+b=na+b=n and S(a)+S(b)S(a)+S(b) is the largest possible among all such pairs.


    In the first example, you can choose, for example, a=17a=17 and b=18b=18, so that S(17)+S(18)=1+7+1+8=17S(17)+S(18)=1+7+1+8=17. It can be shown that it is impossible to get a larger answer.

    In the second test example, you can choose, for example, a=5000000001a=5000000001 and b=4999999999b=4999999999, with S(5000000001)+S(4999999999)=91S(5000000001)+S(4999999999)=91. It can be shown that it is impossible to get a larger answer.

    35
    Output
    17
    Input
    10000000000
    Output
    91

    该题:
    10的12 次方,不能用ll,只能用char 数组。贪心思想:九越多越好,把这个数分成比他少一位数,都是9的数例如:
    100 :99 1;
    也就是从字符串的最后开始往前找(我的做法,不知道从前往后行不行)如果这个字符比九小,例如 23,走到3,发现比9小,那么另一个数这一位就是4(因为你是想把3这一位拆乘9)2就要-1成为1。
    做法中没有讨论遇到108 - 9 的情况,因为这样做每一步都能保证运行到该行时他的值都大于0,最后加上最开头以为数字-‘0’;

    #include <iostream>
    #include <algorithm>
    #include<cstdio>
    #include<stack>
    #include <deque>
    #include <cstdlib>
    #include <cstring>
    #include <string>
    #include <map>
    #include <deque>
    #include <vector>
    using namespace std;
    typedef long long ll;
    map<int,int>mp;
    int main()
    {
        char a[100];
        int i,ans=0;
        scanf("%s",a);
        int a1=strlen(a);
        for(i=a1-1;i>=1;i--)
        {
            if(a[i]=='9')
            {
                ans+=9;
            }
            else
            {
                ans+=a[i]-'0'+10;
                a[i-1]-=1;
            }
        }
        ans+=a[i]-'0';
        printf("%d
    ",ans);
    
    }

    Codeforces 712 c

    一个等边三角形,由大的变成小的要最少多少步,而且保证每一步都是三角形。

    该题应该考虑从小加到大,因为这样加的时候是可以有据可依的(保证是三角形):两边之和大于第三边。然后再用贪心的思想,三个数轮着变成另外两个数相加-1,保证这样是步数最少的。

    如果到了一个数大于要求的边时,break,然后加2,因为要变成等边三角形:

    #include <iostream>
    #include <algorithm>
    #include<cstdio>
    #include<stack>
    #include <deque>
    #include <cstdlib>
    #include <cstring>
    #include <string>
    #include <map>
    #include <deque>
    #include <vector>
    using namespace std;
    typedef long long ll;
    map<int,int>mp;
    int main()
    {
        int a,b;
        scanf("%d%d",&a,&b);
        int x=b,y=b,z=b;
        int flag=1;
        int ans=0;
        while(1)
        {
    
            if(x==a&&y==a&&z==a)
                break;
            if(flag==1)
            {
                flag++;
                x=y+z-1;
                ans++;
                if(x>=a)
                    break;
            }
            if(flag==2)
            {
                ans++;
                flag++;
                y=x+z-1;
                if(y>=a)
                    break;
            }
            if(flag==3)
            {
                ans++;
                flag=1;
                z=x+y-1;
                if(z>=a)
                    break;
            }
        }
        printf("%d
    ",ans+2);
    
    }

    Codeforces 712 B

     这个题就是一个人能上下左右走,最好要回到原点,让你改变他的路径例如,样例给的lruu,你要回去所以u要变成d,问最少要变几次。

    这个题可以考虑对称,从原点开始走,最后回到原点。

    左右对称,抵消掉,剩下的就是左右的差,上下的差,如果他们的和是偶数,则能改变,否在无论如何多一个无法回到原点。

    #include <iostream>
    #include <algorithm>
    #include<cstdio>
    #include<stack>
    #include <deque>
    #include <cstdlib>
    #include <cstring>
    #include <string>
    #include <map>
    #include <deque>
    #include <vector>
    using namespace std;
    typedef long long ll;
    map<int,int>mp;
    int main()
    {
        char a[100100];
        int i,j,ge1=0,ge2=0;
        scanf("%s",a);
        int a1=strlen(a);
        for(i=0; i<=a1-1; i++)
        {
            if(a[i]=='L')
                ge1++;
            if(a[i]=='R')
                ge1--;
            if(a[i]=='U')
                ge2++;
            if(a[i]=='D')
                ge2--;
        }
        if((abs(ge1)+abs(ge2))%2!=0)
            printf("-1
    ");
        else
            printf("%d
    ",(abs(ge1)+abs(ge2))/2);
    
    }
  • 相关阅读:
    第二节:ts变量声明、通用js数据类型、ts新数据类型、ts类型补充
    第一节:TypeScript简介(特点、编译环境、运行模式)、基于webpack 或 ts-node运行ts详解
    第十七节:Vuex4.x 之Module详解(局部状态、命名空间、辅助函数等) 和 补充nexttick用法
    第十六节:Vuex4.x 简介及state、getters、mutations、actions详解(OptionApi 和 CompositionApi)
    第十五节:VueRouter4.x用法之router-link/router-view的v-slot、动态增删路由、路由导航守卫
    第十四节:VueRouter4.x简介、基本用法、路由懒加载(打包分析)、动态路由、路由嵌套、相关Api
    第十三节:Vue3高级之 render/h函数、jsx、自定义指令、teleport、插件
    HTML让内部元素居中
    蓝桥杯 Web 应用开发模拟赛首次公开!参赛选手速进!
    蓝桥杯历年真题你刷了吗?过来人教你逆袭!
  • 原文地址:https://www.cnblogs.com/bhd123/p/9746792.html
Copyright © 2011-2022 走看看