解析:输入n, k,每个人每次从n个sticks取k个,问谁取得次数多,如果先手次数多就输出YES,否则输出NO
代码:
#include<bits/stdc++.h>
#define N 200009
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
int main()
{
LL n, k;
scanf("%lld%lld", &n, &k);
LL num = n % (2 * k);
if(num < k) puts("NO");
else puts("YES");
return 0;
}
解析:昨天晚上WA6,一直不过,今天补的题,我写的比较暴力,1.5s过的,严格应该会超时的,毕竟10^10,*可以匹配空串或者“坏”的串,坏的串就是不包含第一次出现的字母,下面代码中给的测试数据,我就是WA在下面这种情况了,忧伤啊,,,
代码:
#include<bits/stdc++.h>
#define N 200009
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
char s[100009], ch[100009], ss[100009];
map<char, int> mp;
bool judge()
{
int len1 = strlen(s), len2 = strlen(ss), i, l = -1, r;
for(i = 0; s[i]&&ss[i]; i++)
{
if(s[i] == ss[i]) continue;
if(s[i] == '?' && mp[ss[i]]) continue;
if(s[i] == '*')
{
l = i;
break;
}
return false;
}
if(l == -1)
{
if((len1 == len2) || (len1 - len2 == 1 && s[len1-1] == '*'))
return true;
else return false;
}
int j, jj;
for(j = len1 - 1, jj = len2-1; j > l&&jj>=l; j--, jj--)
{
if(s[j] == ss[jj]) continue;
if(s[j] == '?' && mp[ss[jj]]) continue;
return false;
}
if(j == l) r = jj;
else return false;
if(l > r) return true;
for(int k = l; k <= r; k++)
{
if(!mp[ss[k]]) continue;
return false;
}
return true;
}
int main()
{
int n;
mp.clear();
scanf(" %s %s", ch, s);
for(int i = 0; ch[i]; i++) mp[ch[i]] = 1;
scanf("%d", &n);
while(n--)
{
scanf(" %s", ss);
if(judge()) puts("YES");
else puts("NO");
}
return 0;
}
/*
input:
abc
a?a?a*
3
abaca
a
aaaaax
output:
YES
NO
YES
*/