数据范围:1<=n,m<=100000,-1e9<=a[i]<=1e9。Output每组输出一行,表示丢失的数字的个数。Sample Input
5 3 1 3 4 4 6 1 3 8 3 11 12Sample Output
2 2
这里其实是可以不用long long 长整型的,但是我为了保险,还是在代码里面加了长整型,但是这里却卡在了g++的编译规则上面,下面看两个代码,第一个是WA的,第二个是AC的,注意比较两个代码的不同:
#include<cstdio>
#include<map>
using namespace std;
int main(void)
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
map<long long,int> mp;
long long tmp;
for(int i = 0 ; i < m ; ++i){
scanf("%lld",&tmp);
if(tmp>n||tmp<1) continue;
if(mp.find(tmp)==mp.end()) mp[tmp]=i;
}
printf("%d\n",n-mp.size());
}
return 0;
}
#include<cstdio>
#include<map>
using namespace std;
int main(void)
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
map<__int64,int> mp;
__int64 tmp;
for(int i = 0 ; i < m ; ++i){
scanf("%I64d",&tmp);
if(tmp>n||tmp<1) continue;
if(mp.find(tmp)==mp.end()) mp[tmp]=i;
}
printf("%d\n",n-mp.size());
}
return 0;
}
第二个代码我只是将map中和tmp的long long 改成了__int64,输入lld改为 i64d,然后就AC了,至于原因,这个博客已经写的很详细了有兴趣的可以去看看 点击打开链接