Home > Back-end >  The first k n point slope larger value
The first k n point slope larger value

Time:09-24

Any two points together day line, the first k now have N points, and the slope of slope
Type n, k and the coordinates of n points:
# include
# include
# include
using namespace std;


Void ssort (vector X, vector Y, int len)

{
for( int i=0; I{
for(int j=0; J{
If (x [j] & gt; [j x + 1])
{
Swap (x [j], [x + 1]).
Swap ([j] y, y [j + 1));
}
}
}
}
Int getPartition (vector & Nums, int low, int height)
{
Int keyVal=nums [height].
Int I=low - 1;
For (int j=low; J & lt; Height; J++)
{
If (nums [j] & gt;=keyVal)
{
I=I + 1;
Swap (nums [I], nums [j]);
}
}
Swap (nums [I + 1], the nums [height]);
Return the I + 1;
}

//iteration fast row
Void quicksot (vector & Nums, int low, int height) {

If (low{
Int mid=getPartition (nums, low, height);
Quicksot (nums, low, mid - 1);
Quicksot (nums, mid + 1, height);
}
}

Int main ()

{

Int n, k;
Cin> N> k;
Vector x;
Vector y;
Vector Kk.
Int result=0;
Int t1, t2;
for(int i=0; I{
Cin> T1 & gt;> t2;
X.p ush_back (t1);
Y.p ush_back (t2);


}
CoutSsort (x, y, n);

For (int i1=0; I1 & lt; n; I1 + +)
{
For (int j1=i1 + 1; J1 & lt; n; J1 + +)
{
Result=(y (j1) - y/i1)/(x (j1) - x/i1);
CoutKk. Push_back (result);
}
}
Quicksot (kk, 0, kk. The size () - 1);

Cout
return 0;

}
  • Related