The Cow Lineup
The Cow Lineup
https://ac.nowcoder.com/acm/problem/106586
思路
这题用类似进制的思想做,纵所周知,想要表示的几位数,那么在每一位上的
都是可取的.
那么我们直接遍历看是否都存在,看有多少
都存在的段,答案就是这些段
啦.
代码
#include <stdio.h>
#include <string.h>
using namespace std;
const int M=1e4+5;
bool vis[M];
int main()
{
int n,k,num=0,ans=0;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
if(!vis[x]) vis[x]=true,num++;
if(num==k)
ans++,num=0,memset(vis,false,sizeof vis);
}
printf("%d\n",++ans);
return 0;
}
lpt的小屋 文章被收录于专栏
我想要一份甜甜的爱情
阿里云工作强度 603人发布
查看8道真题和解析