传送门

1001 签到题:

  答案为12。

 

1002 丢失的数字:

  思路:考虑到 n 的范围比较小,因此只要开一个 > 100000 的数组来记录在 [1,n] 范围内的数是否出现即可。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int vis[100005];
int main()
{
    int n,m,i,x,ans;
    //freopen("2.in","r",stdin);
    //freopen("2.out","w",stdout);
    while (~scanf("%d%d",&n,&m))
    {
        memset(vis,0,sizeof(vis));
        for (i=1;i<=m;i++)
        {
            scanf("%d",&x);
            if (x>=1&&x<=n) vis[x]=1;
        }
        ans=0;
        for (i=1;i<=n;i++)
            if (vis[i]==0) ans++;
        printf("%d\n",ans);
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
猜你喜欢
  • 2021-04-25
  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案