Advertisement
Guest User

RunTime Checking

a guest
Sep 30th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1. /* -------------------------------- */
  2. /* Name: MD. Khairul Basar          */
  3. /* Institute: HSTU                  */
  4. /* Dept: CSE                        */
  5. /* Email: khairul.basar93@gmail.com */
  6. /* -------------------------------- */
  7.  
  8. #include <bits/stdc++.h>
  9. /* all header files included */
  10.  
  11. #define mod         1000000007
  12. #define pi          acos(-1.0)
  13. #define eps         1e-9
  14.  
  15. #define fs          first
  16. #define sc          second
  17. #define pb(a)       push_back(a)
  18. #define mp(a,b)     make_pair(a,b)
  19. #define sp          printf(" ")
  20. #define nl          printf("\n")
  21.  
  22. #define set0(a)     memset(a,0,sizeof(a))
  23. #define setneg(a)   memset(a,-1,sizeof(a))
  24. #define setinf(a)   memset(a,126,sizeof(a))
  25.  
  26. #define tc1(x)      printf("Case %d: ",x)
  27. #define tc2(x)      printf("Case #%d: ",x)
  28. #define tc3(x)      printf("Case %d:\n",x)
  29. #define tc4(x)      printf("Case #%d:\n",x)
  30.  
  31. #define pr1(x)      cout<<x<<"\n"
  32. #define pr2(x,y)    cout<<x<<" "<<y<<"\n"
  33. #define pr3(x,y,z)  cout<<x<<" "<<y<<" "<<z<<"\n"
  34. /* defining macros */
  35.  
  36. using namespace std;
  37.  
  38. template <class T> inline T bigmod(T b, T p, T m)
  39. {
  40.     T ret;
  41.     if(p==0) return 1;
  42.     if(p&1)
  43.     {
  44.         ret=(bigmod(b,p/2,m)%m);
  45.         return ((b%m)*ret*ret)%m;
  46.     }
  47.     else
  48.     {
  49.         ret=(bigmod(b,p/2,m)%m);
  50.         return (ret*ret)%m;
  51.     }
  52. }
  53. template <class T> inline T _sqrt(T a)
  54. {
  55.     return (T)sqrt((double)a);
  56. }
  57. template <class T, class X> inline T _pow(T a, X b)
  58. {
  59.     T res=1;
  60.     for(int i=1; i<=b; i++)
  61.         res*=a;
  62.     return res;
  63. }
  64. /* template functions */
  65.  
  66. typedef long long LL;
  67. typedef unsigned long long ULL;
  68. typedef pair<int, int>pii;
  69. typedef pair<LL, LL>pll;
  70. typedef pair<double, double>pdd;
  71. typedef vector<int>vi;
  72. typedef vector<LL>vll;
  73. typedef vector<double>vd;
  74. /* type definition */
  75.  
  76. int dx4[]= {1,-1,0,0};
  77. int dy4[]= {0,0,1,-1};
  78. int dx6[]= {0,0,1,-1,0,0};
  79. int dy6[]= {1,-1,0,0,0,0};
  80. int dz6[]= {0,0,0,0,1,-1};
  81. int dx8[]= {1,-1,0,0,-1,1,-1,1};
  82. int dy8[]= {0,0,1,-1,1,1,-1,-1};
  83. int dkx8[]= {-1,1,-1,1,-2,-2,2,2};
  84. int dky8[]= {2,2,-2,-2,1,-1,1,-1};
  85. /* direction array */
  86.  
  87. int tc=1;
  88. const long long int mx=10000;
  89. /* global declaration */
  90.  
  91. int main()
  92. {
  93.     int i,j,n,m,d,a[mx+5],moves,ans,x;
  94.  
  95.     n=100;
  96.     m=100;
  97.     d=1;
  98.     for(i=0; i<n*m; i++)
  99.     {
  100.         a[i]=i+1;
  101.     }
  102.     ans=INT_MAX;
  103.     x=n*m;
  104.     int start=clock();
  105.     for(i=0; i<x; i++)
  106.     {
  107.         moves=0;
  108.         for(j=0; j<x; j++)
  109.         {
  110.             if(i!=j) moves+=abs(a[j]-a[i]);
  111.         }
  112.         ans=min(ans,moves);
  113.     }
  114.     ans=ans/d;
  115.     int finish=clock();
  116.     double duration=(finish-start)/double(CLOCKS_PER_SEC)*1000;
  117.     printf("Run Time: %.0lf ms\n",duration);
  118.  
  119.     return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement