-_lala_- 2016-08-17 11:36 采纳率: 20%
浏览 1979

急求这样的time limit exceeded怎样解决?

An array of length n, with address from 1 to n inclusive, contains entries from the set {1,2,...,n-1} and there's exactly two elements with the same value. Your task is to find out the value.

Input

Input contains several cases.
Each case includes a number n (1<n<=10^6), which is followed by n integers.
The input is ended up with the end of file.

Output

Your must output the value for each case, one per line.

Sample Input
2
1 1
4
1 2 3 2

Sample Output
1
2

 #include <iostream>
#include<cstdio>
using namespace std;


int main(int argc, char** argv) 
{ 
int n;
while(scanf("%d",&n)!=EOF){
    if(n!=-1){
    int *p=new int[n];
    int t,m;
    while(n--){
        cin>>t;
        if(p[t]==0)
        p[t]=1;
        else
        m=t;
    }
    cout<<m<<endl;
    delete p;
}
else
break;
}
    return 0;
}
  • 写回答

2条回答 默认 最新

  • threenewbee 2016-08-17 14:43
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序