staafl

Untitled

Jul 20th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace laser
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. if (File.Exists("input.txt"))
  15. {
  16. Console.SetIn(new StreamReader("input.txt"));
  17. }
  18.  
  19. int n = int.Parse(Console.ReadLine());
  20.  
  21. var list = new LinkedList<int>();
  22. for (int i =1 ; i <= n; i += 1)
  23. {
  24. list.AddLast(i);
  25. }
  26.  
  27. int lastLamp = 0;
  28. int currentTurn = 1;
  29.  
  30. while (list.Count > 0)
  31. {
  32. int step = currentTurn + 1;
  33.  
  34. var node = list.First;
  35.  
  36. var cnt = list.Count;
  37.  
  38. for (int i = 0; i < cnt; i++)
  39. {
  40. var nextNode = node.Next;
  41.  
  42. if (i % step == 0)
  43. {
  44. lastLamp = node.Value;
  45. list.Remove(node);
  46. }
  47.  
  48. node = nextNode;
  49. if (node == null)
  50. break;
  51. }
  52.  
  53. currentTurn += 1;
  54. }
  55.  
  56. Console.WriteLine(lastLamp);
  57.  
  58. for (int i = 0; i < 2; i++)
  59. {
  60. int dx = 1;
  61. int dy = 0;
  62. int x = 0;
  63. int y = 0;
  64.  
  65. var commands = Console.ReadLine();
  66. for (int j = 0; j < 4; j++)
  67. foreach (char command in commands)
  68. {
  69. if (command == 'S')
  70. {
  71. x += dx;
  72. y += dy;
  73. }
  74. else if (command == 'L' || command == 'R')
  75. {
  76. // turn left
  77. if (x == 1)
  78. {
  79. x = 0;
  80. y = 1;
  81. }
  82. else if (x == -1)
  83. {
  84. x = 0;
  85. y = -1;
  86. }
  87. else if (y == 1)
  88. {
  89. x = -1;
  90. y = 0;
  91. }
  92. else if (y == -1)
  93. {
  94. x = 1;
  95. y = 0;
  96. }
  97.  
  98. if (command == 'R')
  99. {
  100. x *= -1;
  101. y *= -1;
  102. }
  103. }
  104.  
  105. }
  106.  
  107. if (x == 0 && y == 0)
  108. Console.WriteLine("bounded");
  109. else
  110. Console.WriteLine("unbounded");
  111. }
  112. }
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment