Advertisement
bartekltg

fir

May 22nd, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. // fir.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <vector>
  6. #include<cstdlib>
  7. #include <cstdio>
  8. #include <ctime>
  9.  
  10.  
  11. using namespace std;
  12.  
  13. class czastka
  14. {
  15. public:
  16.     int x,y,Fx,Fy;
  17.     czastka(int _x,int _y,int _Fx,int _Fy) {x=_x;y=_y;Fx=_Fx;Fy=_Fy;};
  18.     czastka() {x=0;y=0;Fx=0;Fy=0;};
  19. };
  20.  
  21. vector<czastka> particle;
  22.  
  23. void moveParticle()
  24. {
  25.    //  return ;
  26.     int particle_max = particle.size(); //skoro am być tak samo...
  27.  
  28.  
  29.      for(int i=0; i<particle_max; i++)
  30.      {
  31.  
  32.           int nx = particle[i].x + particle[i].Fx;
  33.           int ny = particle[i].y + particle[i].Fy;
  34.  
  35.           particle[i].x = nx;
  36.           particle[i].y = ny;
  37.     }
  38. }
  39.  
  40.  
  41. int main()
  42. {
  43.     int liczba_czastek;
  44.     scanf ("%d",&liczba_czastek);
  45.     particle.resize(liczba_czastek);
  46.     for (int i=0; i<liczba_czastek;i++ )
  47.         particle[i]=czastka(rand(),rand(),rand(),rand());//wypalniamy smieciem
  48.  
  49.     clock_t start = clock();
  50.     for (int j=1;j<1000;j++)
  51.         moveParticle();
  52.     clock_t end = clock();
  53.  
  54.    
  55.     unsigned int akumulator=0;
  56.     for (int i=0; i<liczba_czastek;i++ )
  57.         akumulator+= particle[i].x+particle[i].y; //zbieramy smiecie
  58.  
  59.     printf("trwało %f    %d", ((float)(end-start))/CLOCKS_PER_SEC,akumulator);
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement