Advertisement
juanjo12x

UVA_379_Hi_Q

Aug 5th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <stdio.h>
  4. #include <algorithm>
  5. #include <cstring>
  6. #include <iostream>
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <cstring>
  10. #include <string>
  11. #include <cctype>
  12. #include <stack>
  13. #include <queue>
  14. #include <list>
  15. #include <vector>
  16. #include <map>
  17. #include <set>
  18. #include <sstream>
  19. #include <stdlib.h>
  20. #include <cmath>
  21. #define LL unsigned long long
  22. using namespace std;
  23.  
  24. int pegs[50];
  25.  
  26. int
  27. up(int a) {
  28.     if (a<=3 || a==7 || a==8 || a==12 || a==13) return 0;
  29.     if (a<=6) return a-3;
  30.     if (a<=11) return a-5;
  31.     if (a<=27) return a-7;
  32.     if (a<=30) return a-5;
  33.     return a-3;
  34. }
  35.  
  36. int
  37. down(int a) {
  38.     if (!a || a>=31 || a==21 || a==22 || a==26 || a==27) return 0;
  39.     if (a>=28) return a+3;
  40.     if (a>=23) return a+5;
  41.     if (a>=7) return a+7;
  42.     if (a>=4) return a+5;
  43.     return a+3;
  44. }
  45.  
  46. int
  47. left(int a) {
  48.     if (a<=1 || a==4 || a==7 || a==14 || a==21 || a==28 || a==31) return 0;
  49.     return a-1;
  50. }
  51.  
  52. int right(int a) {
  53.     if (!a || a==3 || a==6 || a==13 || a==20 || a==27 || a==30 || a==33) return 0;
  54.     return a+1;
  55. }
  56.  
  57. bool tratar() {
  58.     int i;
  59.  
  60.     for (i=33; i>=1; i--) {
  61.         if (pegs[i]) continue;
  62.         if (pegs[down(i)] && pegs[down(down(i))]) {
  63.             pegs[down(i)] = pegs[down(down(i))] = 0;
  64.             pegs[i] = 1;
  65.             return true;
  66.         }
  67.         if (pegs[right(i)] && pegs[right(right(i))]) {
  68.             pegs[right(i)] = pegs[right(right(i))] = 0;
  69.             pegs[i] = 1;
  70.             return true;
  71.         }
  72.         if (pegs[left(i)] && pegs[left(left(i))]) {
  73.             pegs[left(i)] = pegs[left(left(i))] = 0;
  74.             pegs[i] = 1;
  75.             return true;
  76.         }
  77.         if (pegs[up(i)] && pegs[up(up(i))]) {
  78.             pegs[up(i)] = pegs[up(up(i))] = 0;
  79.             pegs[i] = 1;
  80.             return true;
  81.         }
  82.     }
  83.     return false;
  84. }
  85.  
  86. void calc() {
  87.     int i;
  88.     int tot=0;
  89.  
  90.     while(tratar());
  91.     for (i=1; i<=33; i++) {
  92.         if (pegs[i]) tot+=i;
  93.     }
  94.     printf("%d\n", tot);
  95. }
  96.  
  97. int main() {
  98.     int i,n;
  99.  
  100.     printf("HI Q OUTPUT\n");
  101.     scanf("%d", &n);
  102.     for (i=0; i<n; i++) {
  103.         int a;
  104.         memset(pegs, 0, sizeof(pegs));
  105.         while (1) {
  106.             scanf("%d", &a);
  107.             if (a==0) {
  108.                 break;
  109.             } else {
  110.                 pegs[a] = 1;
  111.             }
  112.         }
  113.         calc();
  114.     }
  115.     printf("END OF OUTPUT\n");
  116.     return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement