Guest User

Untitled

a guest
May 25th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) throws IOException {
  6. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  7. String input = "";
  8. while(true) {
  9. input = reader.readLine();
  10. if(input.equals("0 0 0")) System.exit(0);
  11. String[] striple = input.split(" ");
  12. int N = Integer.parseInt(striple[0]);
  13. int k = Integer.parseInt(striple[1]);
  14. int m = Integer.parseInt(striple[2]);
  15. int up = -1;
  16. int down = N;
  17. int n = N;
  18. boolean[] left = new boolean[N];
  19. while(n>0) {
  20. int mk = k%n;
  21. int mm = m%n;
  22. if(mk==0) mk=k;
  23. if(mm==0) mm=m;
  24.  
  25. int i = 0;
  26. while(i<mk) {
  27. up = (up+1)%N;
  28. if(!left[up]) {
  29. i++;
  30. }
  31. }
  32. i = 0;
  33. while(i<mm) {
  34. down--;
  35. if(down==-1) down = N-1;
  36. if(!left[down]) {
  37. i++;
  38. }
  39. }
  40. if(up==down) {
  41. n--;
  42. left[up] = true;
  43. int u = up+1;
  44. String res = null;
  45. if(u<10) res = " "+u;
  46. else res = " "+u;
  47. if(n>0) res+=",";
  48. else res+="\n";
  49. System.out.print(res);
  50. } else {
  51. n -= 2;
  52. left[up] = true;
  53. left[down] = true;
  54. int u=up+1;
  55. int d=down+1;
  56. String res = null;
  57. if(u<10) res = " "+u;
  58. else res = " "+u;
  59. if(d<10) res += " "+d;
  60. else res += " "+d;
  61. if(n>0) res+=",";
  62. else res+="\n";
  63. System.out.print(res);
  64. }
  65. }
  66. }
  67. }
  68. }
Add Comment
Please, Sign In to add comment