Codeforces Round #425 (Div. 2)(A+B)

A. Sasha and Sticks
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
It’s one more school day now. Sasha doesn’t like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.

Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws n sticks in a row. After that the players take turns crossing out exactly k sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than k sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.

Input
The first line contains two integers n and k (1 ≤ n, k ≤ 1018, k ≤ n) — the number of sticks drawn by Sasha and the number k — the number of sticks to be crossed out on each turn.

Output
If Sasha wins, print “YES” (without quotes), otherwise print “NO” (without quotes).

You can print each letter in arbitrary case (upper of lower).

Examples
input
1 1
output
YES
input
10 4
output
NO
Note
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can’t make a move, and Sasha wins.

In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can’t make a move. The players make equal number of moves, so Sasha doesn’t win.
題意:n個物品,倆人輪流每次取k個,當剩餘物品

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#define NI  freopen("in.txt","r",stdin);
#define NO  freopen("out.txt","w",stdout);
using namespace std;
typedef long long int ll;
typedef pair<int,int>pa;
const int N=1e5+10;
const int MOD=1e9+7;
const ll INF=1e18;
int read()
{
    int x=0;
    char ch = getchar();
    while('0'>ch||ch>'9')ch=getchar();
    while('0'<=ch&&ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return x;
}
/************************************************************/\
ll a,b;
int main()
{
    cin>>a>>b;
    if((a/b)%2==1)
    puts("YES");
    else
        puts("NO");

}

B. Petya and Exam
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
It’s hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..

There is a glob pattern in the statements (a string consisting of lowercase English letters, characters “?” and ““). It is known that character “” occurs no more than once in the pattern.

Also, n query strings are given, it is required to determine for each of them if the pattern matches it or not.

Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning.

A pattern matches a string if it is possible to replace each character “?” with one good lowercase English letter, and the character “*” (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string.

The good letters are given to Petya. All the others are bad.

Input
The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad.

The second line contains the pattern — a string s of lowercase English letters, characters “?” and “” (1 ≤ |s| ≤ 105). It is guaranteed that character “” occurs in s no more than once.

The third line contains integer n (1 ≤ n ≤ 105) — the number of query strings.

n lines follow, each of them contains single non-empty string consisting of lowercase English letters — a query string.

It is guaranteed that the total length of all query strings is not greater than 105.

Output
Print n lines: in the i-th of them print “YES” if the pattern matches the i-th query string, and “NO” otherwise.

You can choose the case (lower or upper) for each letter arbitrary.

Examples
input
ab
a?a
2
aaa
aab
output
YES
NO
input
abc
a?a?a*
4
abacaba
abaca
apapa
aaaaax
output
NO
YES
NO
YES
Note
In the first example we can replace “?” with good letters “a” and “b”, so we can see that the answer for the first query is “YES”, and the answer for the second query is “NO”, because we can’t match the third letter.

Explanation of the second example.

The first query: “NO”, because character “*” can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string “ba”, in which both letters are good.
The second query: “YES”, because characters “?” can be replaced with corresponding good letters, and character “*” can be replaced with empty string, and the strings will coincide.
The third query: “NO”, because characters “?” can’t be replaced with bad letters.
The fourth query: “YES”, because characters “?” can be replaced with good letters “a”, and character “*” can be replaced with a string of bad letters “x”.
題意:給出一個好串,一個母串,n個子串,問母串能否變成子串。母串中的”?”可以替換成任意一個好串內的字符,母串中的”*”可以替換成任意數量的非好字符,也可替換成空串。
題解:模擬判斷即可
代碼:

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#define NI  freopen("in.txt","r",stdin);
#define NO  freopen("out.txt","w",stdout);
using namespace std;
typedef long long int ll;
typedef pair<int,int>pa;
const int N=1e5+10;
const int MOD=1e9+7;
const ll INF=1e18;
int read()
{
    int x=0;
    char ch = getchar();
    while('0'>ch||ch>'9')ch=getchar();
    while('0'<=ch&&ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return x;
}
/************************************************************/
char a[100],b[N],c[N];
int vis[100];
int q;
int main()
{
    memset(vis,0,sizeof(vis));
    scanf("%s",a);
    int len=strlen(a);
    for(int i=0; i<len; i++)
    {
        vis[a[i]-'a'+1]=1;
    }
    scanf("%s",b);
    int lenb=strlen(b);
    scanf("%d",&q);
    while(q--)
    {
        scanf("%s",c);
        bool flag=true;
        int lenc=strlen(c);
        int cnt=lenc-lenb;
        if(cnt<-1)
        {
            puts("NO");
            continue;
        }
        int i=0;
        int k=0;
        for( ; i<lenb; i++,k++)
        {
            if(b[i]>='a'&&b[i]<='z')
            {
                if(c[k]!=b[i])
                {
                    flag=false;
                    break;
                }
            }
            if(b[i]=='?')
            {
                if(vis[c[k]-'a'+1]==0)
                {
                    flag=false;
                    break;
                }
            }
            if(b[i]=='*')
            {
                if(cnt<0)
                {
                    k--;
                    continue;
                }
                for(int j=0; j<=cnt; j++)
                {
                    if(vis[c[k+j]-'a'+1]!=0)
                    {
                        flag=false;
                        break;
                    }
                }
                k+=cnt;
            }
        }
        if(flag&&i==lenb&&k==lenc) puts("YES");
        else puts("NO");
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章