1. 程式人生 > >比賽題解 (1)—— 思維

比賽題解 (1)—— 思維

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");
    }
}

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);
    }
   
}

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);
    }

}

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");
}