杭电ACM题1001的超时问题
来源:互联网 发布:算法导论有答案吗 编辑:程序博客网 时间:2024/05/29 09:33
Ignatius and the Princess IV
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32767K (Java/Other)
Total Submission(s) : 65 Accepted Submission(s) : 17
"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.
"But what is the characteristic of the special integer?" Ignatius asks.
"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.
Can you find the special integer for Ignatius?
51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1
351
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
简单题,做的时候出现了超时问题,问题是由于cin造成的,用cin输入num会出现超时,但通过scanf函数接受num时可以AC,这个不明白,刚开始学C++,对它的输入输出不是很了解。
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
代码:
/***********************
* 程序名:Ignatius and the Princess IV.cpp
* 功能:ACM
************************/
#include <iostream>
#include <Cstdio>
using namespace std;
int main()
{
int N, num, temp, i;
while(scanf("%d", &N) != EOF) {
int count[32768] = {0};
for(i = 0; i < N; i++) {
scanf("%d", &num);
count[num]++;
if(count[num] >= (N+1)/2) {
temp = num;
}
}
cout<<temp<<endl;
}
return 0;
}
- 杭电ACM题1001的超时问题
- 杭电2089 超时问题
- 杭电ACM题2000遇到的一点问题
- ACM杭电的1093求和问题
- 杭电ACM 1001题
- 杭电acm 大数问题
- 杭电acm 1001
- 杭电ACM 1001
- 杭电ACM 1001
- 杭电ACM 1001
- 杭电ACM 1001
- 杭电ACM----1001
- 杭电acm 数学类型的题
- 【求助】杭电ACM 1001 一道简单问题,老是PE
- 杭电1713 超时
- 杭电2058 超时
- acm 杭电 1001 sum
- hdu 杭电acm 2018母牛问题
- 外链总体思想
- 另一种阶乘问题
- What is Linux System Calls and Library Functions?
- Python文件路径
- git 的patch功能
- 杭电ACM题1001的超时问题
- 创建单链表2
- Linux字符设备驱动_Helloworld x86
- 代码大全2(读书笔本1)
- JAVA 断言
- poj 2503.Babelfish
- 『Linux学习』基本命令篇(二)
- Ruby 有关`迭代器' 与 `递归' 的替换.
- Android getWidth和getMeasuredWidth的正解