比赛题解 (1)—— 思维

1——————————CodeForces 877A

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

题意:给你字符串 s 判断是不是 Alex's friends' name 中的一个,必须是一个

直接暴力就判断好啦

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;

int main()
{
    char s[100];
    int flag=0;
    int sum=0;
    char ss[][10]={"Danil","Olya","Slava","Ann","Nikita"};
    scanf("%s",s);
    int m=strlen(s);
    if(m<=2)
        printf("NO\n");
    else{
        for(int i=0;i<m;i++)
        {
            if(s[i]=='A'&&s[i+1]=='n'&&s[i+2]=='n')
                    sum++;
            else if(s[i]=='D'&&s[i+1]=='a'&&s[i+2]=='n'&&s[i+3]=='i'&&s[i+4]=='l')
                sum++;
            else if(s[i]=='S'&&s[i+1]=='l'&&s[i+2]=='a'&&s[i+3]=='v'&&s[i+4]=='a')
                sum++;
            else if(s[i]=='O'&&s[i+1]=='l'&&s[i+2]=='y'&&s[i+3]=='a')
                sum++;
            else if(s[i]=='N'&&s[i+1]=='i'&&s[i+2]=='k'&&s[i+3]=='i'&&s[i+4]=='t'&&s[i+5]=='a')
                sum++;
            else
                continue;
        }
        if(sum==1)
            printf("YES\n");
        else
            printf("NO\n");
    }
}

2——————————CodeForces 869B

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.

题意:

m!/ n!的末尾数是多少

数据量太大,直接暴力肯定 wrong

思路:

  首先我们可以推出结论,如果b-a≥5的话那最后一位肯定是0,因为b-a≥5的话,就是5个连续的自然数相乘,那其中必有一个为5的倍数(2的倍数就更不用说了) 所以最后一位肯定是0。 如果b-a<5的话,那直接暴力就好

用同余定理求解 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
#define maxx 100000

int main()
{
    LL a,b;
    LL ans=0;
    LL sum[20];
    scanf("%lld %lld",&a,&b);
    int n,m;
    n=a%10;
    m=b%10;
    LL t=b-a;
    if(t>=5)
        printf("0\n");
    else
    {
        LL x,y;
        y=1;
        for(LL i=b; i>a; i--)
        {
            y=((y%10)*(i%10))%10;
        }
        printf("%lld\n",y%10);
    }
   
}

3——————————CodeForces 877C

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 cell n - 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 

 题意:

给你一个 1×n 的地图,地图有 n 的小房子,里边有一个或者多个坦克,你在高空中选择炸其中任意一个房间的坦克

如果这个坦克第一次受到轰炸时,它会移动到与他相邻任意一个房间里,当然如果该房间号是 1 或者是 n 的话,它只能移动到 2 和 n-1

如果是受到第二次轰炸的话,就会永远被摧毁

帮助Slava用   尽可能少   的炸弹摧毁所有坦克

首先,明确一点,你在高空中,看不到每个房间坦克的移动情况,不能根据你自己的控制来决定坦克的移动

所以求的是尽可能少的,而不是最少的数量 

 思路:

如果需要尽可能少的炸弹数量,那么就应该出现这种情况,炸完一个房间之后,这个房间的炸弹去到了相邻的房间,当在轰炸这个房间的时候,可以使原本房间的坦克摧毁,也可以使这个房间的坦克受到第一次伤害,那么怎么选择炸房间才能实现尽可能少的炸弹数呢 ????

我们要知道 偶数的个数是小于等于 奇数的个数的,当炸完偶数的房间号,可以使坦克去到相邻的奇数房间里,然后去炸奇数房间号,原本第一次受到伤害的被摧毁,奇数房间号的移动到与之相邻的偶数房间里,再炸一次偶数房间就可以使所有炸弹销毁

首选 炸完所有的偶数房间号,然后选择炸 奇数房间号 ,在选择炸一次偶数房间号就可以使所有的坦克摧毁

需要的总数 = 2×偶数个数 + 奇数个数

CODE:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
int main()
{
    int n;
    scanf("%d",&n);
    int a=n/2;
    int b=n-a;
    printf("%d\n",a*2+b);
    for(int i=2;i<=n;i+=2)
        printf("%d ",i);
    for(int i=1;i<=n;i+=2)
        printf("%d ",i);
    for(int i=2;i<=n;i+=2){
        if(i<n)
            printf("%d ",i);
        else
            printf("%d\n",i);
    }

}

 4——————————CodeForces 1008B

Description

There are $$$n$$$ rectangles in a row. You can either turn each rectangle by $$$90$$$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.

Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).

Input

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of rectangles.

Each of the next $$$n$$$ lines contains two integers $$$w_i$$$ and $$$h_i$$$ ($$$1 \leq w_i, h_i \leq 10^9$$$) — the width and the height of the $$$i$$$-th rectangle.

Output

Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO".

You can print each letter in any case (upper or lower).

Sample Input

Input

3
3 4
4 6
3 5

Output

YES

Input

2
3 4
5 5

Output

NO

Hint

In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].

In the second test, there is no way the second rectangle will be not higher than the first one.

 题意:

给定几个矩形的宽和高,你可以选择是否将其旋转 90度,实现高度按非上升排序,也就是下降的趋势排序

例如样例 1:

将 第一个旋转后高是 4,可以实现从第一个到最后一个 高依次递减的的趋势

思路:

1、先选择第一个矩形中 宽和高 最大的一个,记为 maxx

   (为什么选最大??————因为按非上升序列排序,第一个保证最大的话,后来有更大的可能实现非上升排序)

2、从第二个往后与前一个比较

  (1)、如果宽和高都小于等于  maxx 的话,则 maxx=max( w[ i ], h[ i ] )

  (2)、如果宽和高有一个小于等于 maxx,有一个大于 maxx ,那么 maxx=min(w[ i ],h [ i ] )

  (3)、如果宽和高都大于 maxx 的话,是不符合题意的,直接跳出循环

CODE:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
#define swap(a,b) a=a+b,b=a-b,a=a-b
const LL MAXX=1e5+10;

LL w[MAXX];
LL h[MAXX];
int main()
{
    LL n;
    scanf("%lld",&n);
    for(LL i=1; i<=n; i++)
        scanf("%lld %lld",&w[i],&h[i]);
    LL maxx=-1;
    LL m;
    m=max(w[1],h[1]);
    for(LL i=2; i<=n; i++)
    {
        if(w[i]<=m&&h[i]<=m)
            m=max(w[i],h[i]);
        else if(w[i]<=m&&h[i]>m||w[i]>m&&h[i]<=m)
            m=min(w[i],h[i]);
        else
        {
            m=-1;
            break;
        }
    }
    if(m==-1)
        printf("NO\n");
    else
        printf("YES\n");
}

猜你喜欢

转载自blog.csdn.net/JKdd123456/article/details/81394928