Advertisement
juanjo12x

UVA_114_Simulation_Wizardry

Aug 1st, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <cctype>
  7. #include <vector>
  8. #include <map>
  9. #include <set>
  10. #include <cmath>
  11. #define For(a) for ( i = 0; i < a; i++ )
  12. #define Rep(a, b) for ( i = a; i <= b; i++ )
  13. #define N 1000000
  14. using namespace std;
  15. struct point{
  16.   bool obs;
  17.   int score;
  18.   int cost;
  19. }Pinball[52][52];
  20. int tot;
  21. int mover(int * x, int * y, int * dir, int * lt)
  22. {
  23.     int newx=*x, newy=*y;
  24.     int score=0;
  25.  
  26.     (*lt)--;
  27.     if (*lt<=0) {
  28.         return 0;/*si la vida se acaba*/
  29.     }
  30.     switch(*dir) {
  31.         case 0: newx += 1; break;
  32.         case 1: newy += 1; break;
  33.         case 2: newx -= 1; break;
  34.         case 3: newy -= 1; break;
  35.     }
  36.     if (Pinball[newx][newy].obs==true) {
  37.         score = Pinball[newx][newy].score;
  38.         *lt -= Pinball[newx][newy].cost;
  39.         newx=*x;
  40.         newy=*y;
  41.         *dir=(*dir+3)%4;
  42.     }
  43.     *x=newx;
  44.     *y=newy;
  45.     return score;
  46. }
  47. int main() {
  48. int m,n,c,p,valor,cost,dir,life,score,x,y;
  49.  scanf("%d %d",&m,&n);
  50.  scanf("%d",&c);
  51.  scanf("%d",&p);
  52.  tot=0;
  53.  for(int i=1;i<=m;i++){
  54.     for(int j=1;j<=n;j++){
  55.         if (i==1 || j==1 || i==m || j==n) {
  56.                 Pinball[i][j].obs=true;
  57.                 Pinball[i][j].score=0;
  58.                 Pinball[i][j].cost=c;
  59.             } else {
  60.                 Pinball[i][j].obs=0;
  61.         }
  62.     }
  63.  }
  64.  for (int i=0;i<p;i++){
  65.     scanf("%d %d %d %d", &x, &y, &valor, &cost);
  66.     Pinball[x][y].obs=true;
  67.     Pinball[x][y].score=valor;
  68.     Pinball[x][y].cost=cost;
  69.  }
  70.  while(scanf("%d %d %d %d",&x,&y,&dir,&life)==4){
  71.     score=0;
  72.     while(life>0){
  73.         score+=mover(&x,&y,&dir,&life);
  74.        
  75.     }
  76.     tot += score;
  77.     printf("%d\n", score);
  78.  }
  79.  printf("%d\n", tot);
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement