Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<vector>
  5. #include<queue>
  6. #include<string>
  7.  
  8. using namespace std;
  9.  
  10. #define MAX_SIZE 100000000
  11.  
  12. int _clock[16];
  13.  
  14. string canTurn[10] = {
  15. // "0123456789012345"
  16. "1110000000000000",
  17. "0001000101010000",
  18. "0000100000100011",
  19. "1000111100000000",
  20. "0000001110101000",
  21. "1010000000000011",
  22. "0001000000000011",
  23. "0000110100000011",
  24. "0111110000000000",
  25. "0001110001000100"
  26. };
  27.  
  28. int result = MAX_SIZE;
  29.  
  30.  
  31. void turnClock(int depth, int cnt) {
  32. if (cnt > result) return;
  33.  
  34. if (depth >= 10) {
  35. for (int i = 0; i < 16; i++) {
  36. if (_clock[i] != 0) return;
  37. }
  38. result = cnt;
  39. return;
  40. }
  41.  
  42. for (int i = 0; i < 4; i++) {
  43. turnClock(depth + 1, cnt + i);
  44. for (int j = 0; j < 16; j++) {
  45. _clock[j] = (_clock[j] + (canTurn[depth][j] == '1' ? 3 : 0)) % 12;
  46. }
  47. }
  48.  
  49. }
  50.  
  51.  
  52. void solve() {
  53. result = MAX_SIZE;
  54.  
  55. for (int i = 0; i < 16; i++) {
  56. scanf("%d", &_clock[i]);
  57. _clock[i] = _clock[i] % 12;
  58. }
  59.  
  60. turnClock(0, 0);
  61.  
  62. printf("%d\n", result == MAX_SIZE ? -1 : result);
  63.  
  64. }
  65.  
  66.  
  67.  
  68. int main() {
  69. int testCase;
  70. scanf("%d", &testCase);
  71.  
  72. for (int i = 0; i < testCase; i++) {
  73. solve();
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement