Yanir7 2019-09-10 09:43 采纳率: 0%
浏览 166

PAT的1041 Be Unique,为什么会 时间超时?!!

题目描述:
PAT 1041 Be Unique
1041 Be Unique
Input Specification:
Each input file contains one test case. Each case contains a line which begins with a positive integer N (≤10^5) and then followed by N bets. The numbers are separated by a space.

Output Specification:
For each test case, print the winning number in a line. If there is no winner, print None instead.

Sample Input 1:
7 5 31 5 88 67 88 17
Sample Output 1:
31
提问:

#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int main(){

    int n;
    while(scanf("%d",&n)!=EOF){
        vector <int> vi;
        for(int i=0;i<n;++i){
            int  tmp;
            scanf("%d",&tmp);
            if(tmp>=1&&tmp<=pow(10,5))   vi.push_back(tmp);
        }
//        bool bigFlag=false;//判断有没有出现唯一数
        int i;
        for(i=0;i<n-1;++i){
            bool flag=false;    //vi[i]是唯一
            for(int j=i+1;j<n;j++){
                if(vi[i]==vi[j]) {
                    vi[j]=0;
                    flag=true;
                }
            }
            if(flag)    vi[i]=0; //不是唯一
            else{//是唯一
                printf("%d\n",vi[i]);
//                bigFlag=true;
                break;
            }
        }//for
        if(i==n-1) printf("None\n");  //整个数组没有唯一的
        vi.clear();

    }
    return 0;
}

  • 写回答

2条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能