zoukankan      html  css  js  c++  java
  • 8月3号水题走一波-个人赛五

    1.Alex and broken contest

    Description

    One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.

    But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.

    It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".

    Names are case sensitive.

    Input

    The only line contains string from lowercase(小写字母) and uppercase(大写字母) letters and "_" symbols of length, not more than 100 — the name of the problem.

    Output

    Print "YES", if problem is from this contest, and "NO" otherwise.

    Sample Input

    Input
    Alex_and_broken_contest
    Output
    NO
    Input
    NikitaAndString
    Output
    YES
    Input
    Danil_and_Olya
    Output
    NO


    题目意思:所给的字符串中只能包含他朋友的一个名字。
    解题思路:当时比赛的时候没多想直接用了笨办法,反正数据量很小,直接一个个的比对。
    之后看到有大神用string中的find做,确实很简单,之前find也学的不清楚,这次贴出代码。
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 char s[110];
     6 int main()
     7 {
     8     int i,len,count;
     9     while(scanf("%s",s)!=EOF)
    10     {
    11         len=strlen(s);
    12         count=0;
    13         for(i=0; i<len; i++)
    14         {
    15             if(s[i]=='D')
    16             {
    17                 if(s[i+1]=='a'&&s[i+2]=='n'&&s[i+3]=='i'&&s[i+4]=='l')
    18                 {
    19                     count++;
    20                 }
    21             }
    22             else if(s[i]=='O')
    23             {
    24                 if(s[i+1]=='l'&&s[i+2]=='y'&&s[i+3]=='a')
    25                 {
    26                     count++;
    27                 }
    28             }
    29             else if(s[i]=='S')
    30             {
    31                 if(s[i+1]=='l'&&s[i+2]=='a'&&s[i+3]=='v'&&s[i+4]=='a')
    32                 {
    33                     count++;
    34                 }
    35             }
    36             else if(s[i]=='A')
    37             {
    38                 if(s[i+1]=='n'&&s[i+2]=='n')
    39                 {
    40                     count++;
    41                 }
    42             }
    43             else if(s[i]=='N')
    44             {
    45                 if(s[i+1]=='i'&&s[i+2]=='k'&&s[i+3]=='i'&&s[i+4]=='t'&&s[i+5]=='a')
    46                 {
    47                     count++;
    48                 }
    49             }
    50         }
    51         if(count==1)
    52         {
    53             printf("YES
    ");
    54         }
    55         else
    56         {
    57             printf("NO
    ");
    58         }
    59     }
    60     return 0;
    61 }

    c++,使用string中的find

    #include <bits/stdc++.h>
    using namespace std;
    vector<string> s;
    int main()
    {
        s.push_back("Danil");
        s.push_back("Olya");
        s.push_back("Slava");
        s.push_back("Ann");
        s.push_back("Nikita");///建立动态数组
        string a;
        cin>>a;
        int res = 0;
        for(int i = 0; i < 5; i++)
        {
            if(a.find(s[i]) != a.npos)
            {
                res++;
                if(a.rfind(s[i]) != a.find(s[i]))///一个字符中出现多个一样的名字
                {
                    res++;
                }
            }
        }
        if(res == 1) 
        {
            cout<<"YES"<<endl;
        }
        else 
        {
            cout<<"NO"<<endl;
        }
        return 0;
    }

    2.The Eternal Immortality

    Description

    Even if the world is full of counterfeits, I still regard it as wonderful.

    Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.

    The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.

    Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, . Note that when b ≥ a this value is always integer.

    As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.

    
    

    Input

    The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).

    
    

    Output

    Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.

    
    

    Sample Input

    Input
    2 4
    Output
    2
    Input
    0 10
    Output
    0
    Input
    107 109
    Output
    2
    
    

    Hint

    In the first example, the last digit of  is 2;

    In the second example, the last digit of  is 0;

    In the third example, the last digit of  is 2.


    解题思路:这道题本身就是一个同余定理的应用a*b%c= (a%c) * (b%c) % c
    这道题的坑点在于不能直接去暴力做,要求的只是最后一位,我们知道只要乘上一个最后一位是0的数,结果的最后一位一定是0!
    所以当b-a>=10的时候一定是0,这样就缩小了范围。
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define ll long long int
     5 using namespace std;
     6 int main()
     7 {
     8     ll a,b,ans,i;
     9     scanf("%lld%lld",&a,&b);
    10     ans=1;
    11     if((b-a)>=10)
    12     {
    13         ans=0;
    14     }
    15     else
    16     {
    17         for(i=a+1;i<=b;i++)
    18     {
    19         ans=(ans*(i%10))%10;
    20     }
    21     ans=ans%10;
    22     }
    23     printf("%lld
    ",ans);
    24     return 0;
    25 }
    
    

      3.Slava and tanks

    Description

    Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very specific map.

    Formally, map is a checkered field of size 1 × n, the cells of which are numbered from 1 to n, in each cell there can be one or several tanks. Slava doesn't know the number of tanks and their positions, because he flies very high, but he can drop a bomb in any cell. All tanks in this cell will be damaged.

    If a tank takes damage for the first time, it instantly moves to one of the neighboring cells (a tank in the cell n can only move to the celln - 1, a tank in the cell 1 can only move to the cell 2). If a tank takes damage for the second time, it's counted as destroyed and never moves again. The tanks move only when they are damaged for the first time, they do not move by themselves.

    Help Slava to destroy all tanks using as few bombs as possible.

    
    

    Input

    The first line contains a single integer n (2 ≤ n ≤ 100 000) — the size of the map.

    
    

    Output

    In the first line print m — the minimum number of bombs Slava needs to destroy all tanks.

    In the second line print m integers k1, k2, ..., km. The number ki means that the i-th bomb should be dropped at the cell ki.

    If there are multiple answers, you can print any of them.

    
    

    Sample Input

    Input
    2
    Output
    3
    2 1 2
    Input
    3
    Output
    4
    2 1 3 2
     
    题目意思:坦克在一个有n个格子的地图上,位置不知道。摧毁坦克需要两次,坦克第一次被炸就会移动到左右相邻的一个位置,问你至少需要轰炸
    多少次才能把坦克彻底炸毁。
    解题思路;当时做这一道题的时候我也没什么思路,就在分析样例,在看第二组样例的时候我发现了一些端倪,因为坦克被炸后会移动到临近的位置
    ,也就是原来在奇数位置上就会变成在偶数位置,原来在偶数位置就会变成在奇数位置。那么想要得到最少轰炸次数,那么就奇数偶数轮番轰炸三次
    就一定会被炸毁的(比如第一次就炸到了,第二次也一定会炸到;第一次炸不到,第二次一定就会炸到,第三次也会炸到)。但为了轰炸次数最少,
    一定是先偶数轰炸,再奇数轰炸,最后偶数轰炸,因为偶数会小于等于奇数的数量。
    
    
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int main()
     6 {
     7     int n,i;
     8     scanf("%d",&n);
     9     printf("%d
    ",n+n/2);
    10     for(i=1;i<=n;i++)
    11     {
    12         if(i%2==0)
    13         {
    14             printf("%d ",i);
    15         }
    16     }
    17     for(i=1;i<=n;i++)
    18     {
    19         if(i%2==1)
    20         {
    21             printf("%d ",i);
    22         }
    23     }
    24     for(i=1;i<=n;i++)
    25     {
    26         if(i%2==0)
    27         {
    28             printf("%d ",i);
    29         }
    30     }
    31     return 0;
    32 }
    
    
    
     
  • 相关阅读:
    LiteMDA中支持Generic的BusinessObjectFactory实现
    Domain Object Layer Design and Sample Code for LiteMDA
    [BuildRelease Management]FinalBuilder
    Java RMI之HelloWorld
    深入浅出之正则表达式[转]
    Linux中的sh+source+export
    Scrum资料收集
    [MySQL]安装和启动
    .NET Remoting之Helloworld
    [在windows上使用Unix工具]SUA+Interix+SFU+Utilities and SDK for UNIXbased Applications
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/9426022.html
Copyright © 2011-2022 走看看