Guest User

Untitled

a guest
Apr 19th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CIRCLE
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int[] arr = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
  12. int N = arr[0];
  13. int K = arr[1];
  14. int result = 0;
  15. int currentposition = 0;
  16. int del = 0;
  17. List<int> list = new List<int>();
  18. List<int> list2 = new List<int>();
  19.  
  20.  
  21. for (int i=0; i<N; i++)
  22. {
  23. int a = int.Parse(Console.ReadLine());
  24. list.Add(a);
  25. }
  26.  
  27. for(int i=0; i<list.Count;i++)
  28. {
  29. list2.Add(i);
  30. }
  31.  
  32.  
  33. int b = list.Count;
  34.  
  35.  
  36. while(list.Count>1)
  37. {
  38. if (list.Count == b)
  39. {
  40.  
  41. result = K + currentposition;
  42. }
  43. else
  44. {
  45.  
  46. result = del + currentposition;
  47. }
  48. while(result>list.Count)
  49. {
  50.  
  51. result -= list.Count;
  52. }
  53. del = list[result - 1];
  54.  
  55. currentposition = result - 1;
  56. list2.Remove(list2[currentposition]);
  57. list.RemoveAt(currentposition);
  58.  
  59.  
  60. }
  61. //Console.WriteLine(String.Join("",list));
  62. Console.WriteLine(list2[0]+1);
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment