time limit exceeded!!为什么???

chuchuzinnia 2008-05-27 05:26:02

#include<stdio.h>
int main(){
int i,n,a[2];
for(i=0;i<2;i++)
{
scanf("%d",&n);
a[i]=(1+n)*n/2;
}
for(i=0;i<2;i++)
{
printf("%d\n\n",a[i]);
}
return 0;
}

怎么会time limit exceeded呢??
...全文
822 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
chuchuzinnia 2008-05-28
  • 打赏
  • 举报
回复
明白了,谢谢!
chuchuzinnia 2008-05-28
  • 打赏
  • 举报
回复
11
hedoudou 2008-05-28
  • 打赏
  • 举报
回复
我gcc编译,linux下面没有问题
xkyx_cn 2008-05-28
  • 打赏
  • 举报
回复
这个代码是Accepted的, 你对比一下


#include <stdio.h>

int main()
{
unsigned int a, sum;
while (EOF != scanf("%u", &a))
{
sum = 0;
sum = (a + 1) * a / 2;

printf("%d\n\n", sum);
}

return 0;
}
chuchuzinnia 2008-05-28
  • 打赏
  • 举报
回复

#include<stdio.h>
int main(){
int n,m;
scanf("%d %d",&n,&m);
printf("%d\n\n%d\n",(1+n)*n/2,(1+m)*m/2);
return 0;
}

这样也不对啊,结果是wrong answer!
chuchuzinnia 2008-05-28
  • 打赏
  • 举报
回复
这是题目要求的呀!
chuchuzinnia 2008-05-28
  • 打赏
  • 举报
回复
那应该怎么写呢?
lionc650 2008-05-28
  • 打赏
  • 举报
回复
lz很逗.....为何还用for循环呢...
chuchuzinnia 2008-05-28
  • 打赏
  • 举报
回复
怎么页面刷新了也看不到回复啊?
SammyLan 2008-05-28
  • 打赏
  • 举报
回复
时间复杂度为O(1)的算法给你写成O(N)了,能不超时么
chuchuzinnia 2008-05-28
  • 打赏
  • 举报
回复
你说说看那,为什么一看就超时了?我怎么不知道!
SammyLan 2008-05-27
  • 打赏
  • 举报
回复
楼主没有学过等差数列么..........
一看就超时了(=_=)
chuchuzinnia 2008-05-27
  • 打赏
  • 举报
回复
我发现杭电的ACM的网站有问题,提交的结果即使正确都会有这样那样的毛病!
chuchuzinnia 2008-05-27
  • 打赏
  • 举报
回复
怎么看不到回复啊?郁闷!!!
fangfei_119 2008-05-27
  • 打赏
  • 举报
回复
VC运行没有问题.a[i]在int范围运行正常.
ORA-00040: active time limit exceeded - call aborted
Cause: The Resource Manager SWITCH_TIME limit was exceeded.
Action: Reduce the complexity of the update or query, or contact your database administrator for more information.
ORA-00041: active time limit exceeded - session terminated
Cause: The Resource Manager SWITCH_TIME limit was exceeded.
Action: Reduce the complexity of the update or query, or contact your database administrator for more information.
chuchuzinnia 2008-05-27
  • 打赏
  • 举报
回复
Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.



Input
The input will consist of a series of integers n, one integer per line.



Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.



Sample Input
1
100


Sample Output
1

5050
K行天下 2008-05-27
  • 打赏
  • 举报
回复
我运行一次没有错误啊。Dev C++
xkyx_cn 2008-05-27
  • 打赏
  • 举报
回复
题目?
条件?
chuchuzinnia 2008-05-27
  • 打赏
  • 举报
回复
自己顶下!!

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧