博客
关于我
Codeforces Round #615 (Div. 3) D. MEX maximizing(思维好题)
阅读量:400 次
发布时间:2019-03-05

本文共 385 字,大约阅读时间需要 1 分钟。

在这里插入图片描述
在这里插入图片描述
题意:给定q次询问和x,每次询问都会加入一个数到数组(数组初始为空),你每次可以对数组中的任一数进行+x和-x的操作,问你当前数组未出现的最小整数。
思路:连E和F都做出来了居然卡在这一题,感觉自己好像思维能力和观察能力不行。。。。
其实每次可以无限加X和减去X就应该想到结果只会对x的模数有影响,找空位就行了。

#include
using namespace std;const int maxn=4e5+10;int a[maxn];int main(){ int q,x,t,ans=0; scanf("%d%d",&q,&x); while(q--) { scanf("%d",&t); a[t%x]++; while(a[ans%x]) a[ans%x]--,ans++; printf("%d\n",ans); } }

转载地址:http://foewz.baihongyu.com/

你可能感兴趣的文章
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>