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 drawsn sticks in a row. After that the players take turns crossing out exactlyk sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less thank 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.
The first line contains two integers n and k (1 ≤ n, k ≤ 1018,k ≤ n) — the number of sticks drawn by Sasha and the numberk — the number of sticks to be crossed out on each turn.
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower).
1 1
YES
10 4
NO
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 only2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
场场都是掉分专场。。。
题目大意:给定 n 个物品,两人轮流拿,每次只能必须拿 k 个,轮到谁没得拿就输了。
n / k 是奇数就是先手赢,偶数后手赢。
#include<cstdio>
using namespace std;
int main()
{
long long n,k;
scanf("%I64d %I64d",&n,&k);
n = n / k;
if(n & 1) printf("YES\n");
else printf("NO\n");
return 0;
}
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 thatthe special pattern characters differ from their usual meaning.
A pattern matches a string if it is possible to replace each character "?" with onegood lowercase English letter, and the character "*" (if there is one) with any, including empty, string ofbad 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.
The first line contains a string with length from1 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 than105.
Print n lines: in thei-th of them print "YES" if the pattern matches thei-th query string, and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrary.
,第二个不含,问两个串可能相等吗。
模拟。。。改了 n 次才过了。没考虑 可以匹配时‘ * ’打头和结尾的情况,以及‘ * ’在中间为空时的情况。特判一下就过了。
在做的时候为简化思路,只考虑 YES 的情况,其他即为 NO。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 1e5 + 5;
char a[maxn],b[maxn];
map<char,int> c;
int main()
{
int n;
scanf("%s",a);
for(int i = 0;a[i] != '\0'; ++i) c[a[i]] = true;
scanf("%s %d",a,&n);
int l1 = strlen(a);
while(n--)
{
scanf(" %s",b);
int l,r,loc,l2 = strlen(b);
int i = 0,j = 0,x,y;
while(i < l1 && j < l2 && (a[i] == b[j] || a[i] == '?' && c[b[j]])) ++i,++j;
x = i,l = j;
if(i == l1 && i == j && (a[i] == b[j] || a[i] == '?' && c[b[j]]))
{
printf("YES\n");
continue;
}
if(i == l1 - 1 && a[i] == '*' && b[i] == '\0')
{
printf("YES\n");
continue;
}
i = l1 - 1,j = l2 - 1;
while(i >= 0 && j >= 0 && (a[i] == b[j] || a[i] == '?' && c[b[j]])) --i,--j;
if(i == 0 && j == -1 && a[i] == '*')
{
printf("YES\n");
continue;
}
y = i,r = j;
if(a[x] == a[y] && a[x] == '*' && l - r == 1)
{
printf("YES\n");
continue;
}
if(a[x] == '*' && a[y] == '*' && l <= r)
{
int t = l;
while(t <= r && !c[b[t]]) ++t;
if(t > r || l - r == 1) printf("YES\n");
else printf("NO\n");
}
else printf("NO\n");
}
}