Home > Back-end >  CSP bo, who is a great god help me have a look at ahhh
CSP bo, who is a great god help me have a look at ahhh

Time:11-20

Did not know where is the problem? The code below
#include
using namespace std;

Int main ()
{
Int n=0, a=0, b=0;
Int consult=0;
Cin> n> A> b;
Int indew_u [a]={0}, value_u [a]={0}, indew_v [b]={0}, value_v [b]={0};
Int I=0, j=0;
for(i=0; iCin> Indew_u [I] & gt;> Value_u [I];
}
for(j=0; jCin> Indew_v [j] & gt;> Value_v [j];
}
i=0;
j=0;
while(i{
If (indew_u [I] i++;
Else if (indew_u [I] & gt; Indew_v [j])
j++;
Else if (indew_u [I]==indew_v [j])
{
Consult +=value_u value_v [I] * [j];
i++;
j++;
}
}
Coutreturn 0;
}


Initially has been running a timeout, 30 points, and then I put the double loop into a single, and display operation error, don't know what wrong?

CodePudding user response:

Dynamic array to use new or malloc allocates memory
Int indew_u [a]={0}, value_u [a]={0}, indew_v [b]={0}, value_v [b]={0};
Change
Int * indew_u=new int [a] {0}, * value_u=new int [a] {0}, * indew_v=new int [b] {0}, * value_v=new int [b] {0};

Finally, don't forget to release the memory
The delete [] indew_u;
The delete [] value_u;
The delete [] indew_v;
The delete [] value_v;

CodePudding user response:

reference 1st floor qybao response:
dynamic array to use new or malloc allocates memory
Int indew_u [a]={0}, value_u [a]={0}, indew_v [b]={0}, value_v [b]={0};
Change
Int * indew_u=new int [a] {0}, * value_u=new int [a] {0}, * indew_v=new int [b] {0}, * value_v=new int [b] {0};

Finally, don't forget to release the memory
The delete [] indew_u;
The delete [] value_u;
The delete [] indew_v;
The delete [] value_v;

This method tried, can't

CodePudding user response:

refer to the second floor alone ° response:
this method tried, no


Look at your screenshots have a C compiler, you can forget the new, using the standard C malloc
Int indew_u [a]={0}, value_u [a]={0}, indew_v [b]={0}, value_v [b]={0};
Change
Int * indew_u=(int *) malloc sizeof (n) (int) *, * value_u=(int *) malloc sizeof (n) (int) *, * indew_v=(int *) malloc sizeof (n) (int) *, * value_v=(int *) malloc (sizeof (int) * n);

Finally released in free memory

In addition, the old C compiler, only support variables defined in the beginning, so int I, j also moved to the beginning, cin, cout also change the scanf and printf

CodePudding user response:

reference qybao reply: 3/f
Quote: refer to the second floor alone ° response:

This method tried, no


Look at your screenshots have a C compiler, you can forget the new, using the standard C malloc
Int indew_u [a]={0}, value_u [a]={0}, indew_v [b]={0}, value_v [b]={0};
Change
Int * indew_u=(int *) malloc sizeof (n) (int) *, * value_u=(int *) malloc sizeof (n) (int) *, * indew_v=(int *) malloc sizeof (n) (int) *, * value_v=(int *) malloc (sizeof (int) * n);

Finally released in free memory

In addition, the old C compiler, only support variables defined in the beginning, so int I, j also moved to the beginning, cin, cout also change the scanf and printf

No, I use the c is another version of the c language to write??

CodePudding user response:

The
reference 4 floor alone ° response:
no, I use the c is another version of the c language to write?

It does not know the
Run code logic no problem, no timeouts, didn't super memory, don't know where is the score?
Don't is beyond the scope of int?
Vi<=10 ^ 6, ui<=10 ^ 6, vi * ui<=10 ^ 12 really beyond the scope of int, but it was child tasks, subtasks also calculate in score points?

CodePudding user response:

reference 5 floor qybao reply:
Quote: refer to 4th floor alone ° response:

No, I use the c is another version of the c language to write?

It does not know the
Run code logic no problem, no timeouts, didn't super memory, don't know where is the score?
Don't is beyond the scope of int?
Vi<=10 ^ 6, ui<=10 ^ 6, vi * ui<=10 ^ 12 really beyond the scope of int, but it was child tasks, subtasks also calculate in score points?

Not clear, change to be long or not long long
  • Related