Home > other >  1115: information orsay a histogram 90 points algorithm timeout for help
1115: information orsay a histogram 90 points algorithm timeout for help

Time:12-10


1115: histograms
Time limit: 1000 ms memory limit: 65536 KB
Submit number: 21217 by counting: 13727
[title description]
Given a non-negative integer array, a statistical inside the occurrences of each number, we only counted array in the largest number,

Suppose Fmax (Fmax<10000) is one of the largest number in the array, so we only statistics {0,... Count the number of occurrences of each Fmax},

[enter]
The first line n is the size of the array, 1 n 10000 or less, or less

Followed by a line is an array of n elements,

[output]
Output each of the number of occurrences in sequence, a line a number, if not, is 0,

For example in the array, the largest number is 3, so we only statistics,1,2,3 {0} occurrence frequency,

[input sample]
5
1 2 3 1
[output sample]
0
3
1
1
my code:
 # include 
using namespace std;
Int n, a [10001], max1=0, b, num;
Int main ()
{
Cin> n;
for(int i=1; i<=n; I++) the scanf (" % d ", & amp; A [I]);
for(int i=1; i<=n; I++)
{
If (a [I] & gt; Max1)
{
Max1=a, [I].
B=I;
}

}
for(int j=0; j<=max1; J++)
{
num=0;
for(int i=1; i<=n; I++)
{
If (a==[I] j) num++;
}
Cout}
return 0;
}

run results:
[1115] the program runs the results

User name:? 15997682622, title number: 1115, run number: 9148291, code length: 369 bytes

Through the

Test point result memory time
Test point 1 answer correct 456 KB 6 ms
Test point 2 answers correct 448 KB 10 ms
Test point 3 answers correct 448 KB 8 ms
Test point 4 answers correct 472 KB 80 ms
Test point 5 answers correct 464 KB 237 ms
Test point 6 answers right 460 KB 341 ms
Test point 7 answer right 480 KB 698 ms
Test point 8 answers right 500 KB 558 ms
Test point 9 answers right 504 KB 749 ms
Test point 10 answer right 508 KB 759 ms

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Los valley on timeout, a pass through, please have a look who can be further optimized, thank you

CodePudding user response:

I think, a [] array first reset (see can use function is preferred to use memset () or loop) and then used to store the number of the count, when the input data to determine the nonnegative after a [x] + +; After the input to the results of a loop output, at most three single, you this code has a twofold cycle, once a large amount of data, time will increase,
  • Related