标题:为什么这份代码提交显示运行错误?
取消只看楼主
青蝶
Rank: 2
等 级:论坛游民
帖 子:160
专家分:51
注 册:2018-2-4
结帖率:92%
已结贴  问题点数:5 回复次数:0 
为什么这份代码提交显示运行错误?
题目链接:http://acm.xidian.
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<iomanip>
#define LL long long
#define pi 3.14159
using namespace std;

int n;
LL a[200010],p[35],ans[5];
set<LL> s;

void init(){
    int i;
    LL s=1;;
    p[0]=1;
    for(i=1;i<=31;i++){
        s*=2;
        p[i]=s;
    }
}

int main(void){
    int i,j,l;
    init();
    while(scanf("%d",&n)!=EOF){
        s.clear();
        for(i=1;i<=n;i++){
            scanf("%lld",&a[i]);
            s.insert(a[i]);
        }
        sort(a+1,a+1+n);
        l=0;
        for(i=1;i<=n;i++){
            if(i!=1 && a[i]==a[i-1]) continue;
            for(j=0;j<=31;j++){
                if(s.count(a[i]+p[j]) && s.count(a[i]+2*p[j])){
                    ans[l]=a[i];
                    l++;
                    ans[l]=a[i]+p[j];
                    l++;
                    ans[l]=a[i]+2*p[j];
                    break;
                }
                if(l==0 && s.count(a[i]+p[j])){
                    ans[l]=a[i];
                    l++;
                    ans[l]=a[i]+p[j];
                }
            }
            if(l==2) break;
        }
        if(l==0) printf("1\n%lld\n",a[1]);
        else if(l==1){
           printf("2\n%lld %lld\n",ans[0],ans[1]);
        }
        else printf("3\n%lld %lld %lld\n",ans[0],ans[1],ans[2]);
    }
    return 0;
}
        
        
搜索更多相关主题的帖子: 代码 include int for i++ 
2019-01-21 00:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-492774-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.174227 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved