Showing posts with label collision. Show all posts
Showing posts with label collision. Show all posts

Monday, February 24, 2020

POJ.2674 Linear world

1.Problem
http://poj.org/problem?id=2674

2.Idea
When 2 animal meets, they exchanges the name and pass thru each other.

3.Source
 #define maxn 32005  
 int dir[maxn];  
 double pos;  
 char name[maxn][300];  
 int n;  
 double len, v;  
 int main()  
 {  
      while (~scanf("%d", &n)) {  
           if (!n) break;  
           scanf("%lf %lf", &len, &v);  
           char ch;  
           int id;  
           double t = -1;  
           for (int i = 0; i < n; i++) {  
                ch = getchar();  
                while (ch == '\n' || ch == ' ') ch = getchar();  
                if (ch == 'p' || ch == 'P')  
                     dir[i] = 1;  
                else dir[i] = -1;  
                scanf("%lf", &pos);  
                scanf("%s", name[i]);  
                double tmp;  
                if (dir[i] == 1)  
                     tmp = (len - pos);  
                else  
                     tmp = pos;  
                if (tmp > t) {  
                     t = tmp;  
                     id = i;  
                }  
           }  
           int cnt = 0;  
           if (dir[id]>0) {  
                for (int i = id + 1; i < n; i++)  
                     if (dir[i]<0)  
                          cnt++;  
           }  
           else {  
                for (int i = id - 1; i >= 0; i--)  
                     if (dir[i]>0)  
                          cnt++;  
           }  
           if (dir[id]>0)  
                id += cnt;  
           else  
                id -= cnt;  
           t = t / v;  
           printf("%13.2lf %s\n", (int)(t * 100) / 100.0, name[id]);  
      }  
      return 0;  
 }  

POJ.3684 Physics Experiment

1.Problem
http://poj.org/problem?id=3684

2.Idea
Assume each of ball is transparent and could pass by one another when collide.

3.Source
 #define MAX_N 111  
 const double g = 10.0;  
 int N, H, R, T;  
 double y[MAX_N];  
 double calc(int T)  
 {  
      if (T < 0) return H;  
      double t = sqrt(2 * H / g);  
      int k = int(T / t);  
      if (k % 2 == 0) {  
           double d = T - k*d;  
           return H - g * d *d / 2;  
      }  
      else {  
           double d = k * t + t - T;  
           return H - g * d *d / 2;  
      }  
 }  
 void solve()  
 {  
      for (int i = 0; i < N; i++) y[i] = calc(T - i);  
      sort(y, y + N);  
      for (int i = 0; i < N; i++) {  
           printf("%.2f%c", y[i] + 2 * R * i / 100.0, i + 1 == N ? '\n' : ' ');  
      }  
 }  
 int main()  
 {  
      int c;  
      cin >> c;  
      while (c--) {  
           cin >> N >> H >> R >> T;  
           solve();  
      }  
      return 0;  
 }