Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a).
The first line contains integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 9). The i-th of the following n lines contains integer ai without leading zeroes (1 ≤ ai ≤ 109).
Print a single integer — the number of k-good numbers in a.
10 6 1234560 1234560 1234560 1234560 1234560 1234560 1234560 1234560 1234560 1234560
10
2 1 1 10
1
A题其实是个大大的水题,无奈好久不打CF,今天集体犯二了,WA了一次,给定n,k,然后输入n个数(我把这些数当做字符串处理了);
对于每个数,允许有的数字某位置上的数字大于k,但是前提是必须所有0-k之间的数要出现在给定数字当中,如:n=2,k=1,输入1,则由于没有出现0-1的所有数字,所以说这个数字不合法,如果合法,则记录答案+1,否则检查下一个数字即可。
/**********************
* author:crazy_石头
* Pro:CF Round 213 div2.A
* algorithm:瞎搞
* Time:15ms
* Judge Status:Accepted
***********************/
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
using namespace std;
#define rep(i,h,n) for(int i=(h);i<=(n);i++)
#define ms(a,b) memset((a),(b),sizeof(a))
#define eps 1e-6
#define INF 1<<29
const int maxn=100000+5;
char a[maxn];
int vis[maxn];
int n,k;
int min(int a,int b)
{
return a<b?a:b;
}
int main()
{
int cnt=0,ok=0,tmp;
scanf("%d%d",&n,&k);
while(n--)
{
scanf("%s",a);
ms(vis,0);
int len=strlen(a);
rep(i,0,len-1)
vis[a[i]-'0']++;
tmp=INF;
rep(i,0,k)
tmp=min(tmp,vis[i]);
cnt+=tmp>0;
}
printf("%d\n",cnt);
return 0;
}
B是个超级水题,我艹,求最长的Fib序列;
/**********************
* author:crazy_石头
* Pro:CF Round 213 div2.B
* algorithm:水
* Time:15ms
* Judge Status:Accepted
***********************/
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
using namespace std;
#define rep(i,h,n) for(int i=(h);i<=(n);i++)
#define ms(a,b) memset((a),(b),sizeof(a))
#define eps 1e-6
#define INF 1<<29
const int maxn=100000+5;
int a[maxn];
int main()
{
int n,i,len;
scanf("%d",&n);
int max=(n>=2)? 2: n;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i>=2&&a[i]==a[i-1]+a[i-2])
{
len++;
if(len>max)
max=len;
}
else
len=2;
}
printf("%d\n",max);
return 0;
}
C题是暴力瞎搞。。
今天虽然前面做了三个题目,可是后面半小时直接酱油了T_T,DE没有思路,以后比赛争取拿下DE,要AK div2!!
/**********************
* author:crazy_石头
* Pro:CF Round 213 div2.C
* algorithm:暴力
* Time:31ms
* Judge Status:Accepted
***********************/
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
using namespace std;
#define rep(i,h,n) for(int i=(h);i<=(n);i++)
#define ms(a,b) memset((a),(b),sizeof(a))
#define eps 1e-6
#define INF 1<<29
#define LL __int64
const int maxn=100000+5;
char a[maxn];
int sum[maxn],tmp[maxn];
int m,n;
int main()
{
scanf("%d%s",&m,a);
n=strlen(a);
rep(i,0,n-1)
tmp[i]=a[i]-'0';
ms(sum,0);
rep(i,0,n-1)
{
int cur=0;
for(int j=i;j<n;j++)
{
cur+=tmp[j];
sum[cur]++;
}
}
LL ans=0;
rep(i,0,n-1)
{
int s=0;
for(int j=i;j<n;j++)
{
s+=tmp[j];
if(s>0&&m%s==0&&m/s<=9*n)
ans+=sum[m/s];
else if(s==0&&m==0)
ans+=(n*(n+1)/2);
}
}
cout<<ans<<endl;
return 0;}