当前位置: 代码迷 >> C语言 >> [求助]这是错在了那里?
  详细解决方案

[求助]这是错在了那里?

热度:223   发布时间:2006-12-09 17:32:12.0
[求助]这是错在了那里?

大家看看这道题,我感觉我没有做错!为什么总是wrong anwser 呢!
Number sequence

--------------------------------------------------------------------------------

Time limit: 1sec. Submitted: 31
Memory limit: 64M Accepted: 8

Source : SCU Programming Contest 2006 Final

--------------------------------------------------------------------------------

Given a number sequence which has N element(s), please calculate the number of different collocation for three number Ai, Aj, Ak, which satisfy that Ai < Aj > Ak and i < j < k.

Input
The first line is an integer N (N <= 50000). The second line contains N integer(s): A1, A2, ..., An(0 <= Ai <= 32768).

Output
There is only one number, which is the the number of different collocation.

Sample Input
5
1 2 3 4 1

Sample Output
6






#include <stdio.h>
#define N 1000

int main(void)
{
long s;
int str1[N], i, j, k = 1, num = 0;

scanf("%ld", &s);
for(i = 0;i < s;i ++)
scanf("%d", &str1[i]);
for(k = 1;k < s - 1;k ++)
for(i = 0;i < k;i ++)
for(j = k + 1;j < s;j ++)
{
if(str1[k] > str1[i]&&str1[k] >str1[j])
num ++;
}
printf("%d\n", num);

return 0;

}

搜索更多相关的解决方案: sequence  limit  number  collocation  SCU  

----------------解决方案--------------------------------------------------------

有谁能翻译一下?


----------------解决方案--------------------------------------------------------

没看你的程序,但一点你就错了
N (N <= 50000). The second line contains N integer(s): A1, A2, ..., An(0 <= Ai <= 32768).
而你定义的数组才多大.


----------------解决方案--------------------------------------------------------
楼上,lz说总是错误,一定还有其它原因的
----------------解决方案--------------------------------------------------------
现在去吃饭,所以没看程序,等回来再帮LZ看看
不好意思哈.
----------------解决方案--------------------------------------------------------
我数组也定义过很大!但是还是错误!
这道题的大概意思是先输入一个数字,是一个数列当中元素的个数!输入整个数列之后!判断这个数列中的三个数,要求其中中间的数要大于两边的数!Ai < Aj > Ak i < j < k这三个数还要求是按原数列当中的顺序排列!
----------------解决方案--------------------------------------------------------
呵呵!没有关系!
----------------解决方案--------------------------------------------------------

#include <stdio.h>
#define N 4000

int main(void)
{
long s;
int str1[N]={0},i,j,k;
long num=0;

scanf("%ld", &s);
for(i=0L;i<s;i++)
scanf("%d",&str1[i]);
for(k=1;k<s-1;k++)
for(i=0;i<k;i++)
for(j=k+1;j<s;j++)
if(str1[k]>str1[i] && str1[k]>str1[j]) num++;
printf("%ld\n",num);
getch();
return 0;
}


----------------解决方案--------------------------------------------------------

我交了,还是错误!


----------------解决方案--------------------------------------------------------

#include<stdio.h>

int main()
{
int i,j,k,n;
unsigned int a[50000];
long count=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-2;i++)
{
for(j=i+1;j<n-1;j++)
{
for(k=j+1;k<n;k++)
{
if(a[i]<a[j]&&a[j]>a[k])
{
count++;
}
}
}
}
printf("%ld\n",count);
return (0);
}

/*估计会超时*/


----------------解决方案--------------------------------------------------------
  相关解决方案