SHARE
TWEET

Untitled

a guest Dec 11th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. int small(int A[],int k,int x,int D,int y)
  9. {
  10.     int e=y;
  11.     int skirt=abs(A[e]-x);
  12.     for(int q=0;q<k;q++)
  13.         if(A[q]<=x+D&&A[q]>=x-D&&abs(A[q]-x)<=skirt)
  14.         {
  15.             if(abs(A[q]-x)<skirt)
  16.             {
  17.                 e=q;
  18.                 skirt=abs(A[e]-x);
  19.             }
  20.             else if(A[q]<A[e])
  21.                 e=q;
  22.         }
  23.     return e;
  24. }
  25. int main(){
  26.     ifstream in("svarstykles-vyr.in");
  27.     ofstream out("svarstykles-vyr.out");
  28.     int D,N,k=1,x;
  29.     in>>N>>D;
  30.     int A[N]={ };
  31.     in>>x;
  32.     A[k-1]=x;
  33.     for(int i=0;i<N-1;i++)
  34.     {
  35.         in>>x;
  36.         for(int y=0;y<k;y++)
  37.         {
  38.             if(abs(A[y]-x)<=D)
  39.             {
  40.                 A[small(A,k,x,D,y)]=x;
  41.                 break;
  42.             }
  43.             else if(k-y==1)
  44.             {
  45.                 A[k]=x;
  46.                 k++;
  47.             }
  48.         }
  49.         //out<<A[0]<<"\n"<<A[1]<<"\n"<<A[2]<<"\n"<<A[3]<<"\n"<<A[4]<<"\n"<<A[5]<<"\n"<<A[6]<<"\n"<<A[7]<<"\n"<<"\n";
  50.     }
  51.     out<<k;
  52.  
  53.     return 0;
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top