fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace COMP252A1
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Console.Write("n=");
  13. int n = int.Parse(Console.ReadLine());
  14. Console.Write("w=");
  15. int w = int.Parse(Console.ReadLine());
  16.  
  17. List<char[]> seq = piano(n, w);
  18. foreach (char[] cs in seq)
  19. Console.WriteLine(cs);
  20.  
  21. Console.Read();
  22. }
  23.  
  24. static void Q1()
  25. {
  26. int[] gray = new int[256];
  27.  
  28. for (int i = 0; i < 256; i++)
  29. {
  30. for (int j = 128; j > 0; j >>= 1)
  31. {
  32. gray[i] = gray[i] | ((((i & j) != 0) ^ ((i & (j << 1)) != 0)) ? j : 0);
  33. Console.Write((((i & j) != 0) ^ ((i & (j << 1)) != 0)) ? "#" : "-");
  34. //Console.Write(((i & j) != 0) ? 1 : 0);
  35. }
  36. Console.WriteLine();
  37. }
  38.  
  39. //for (int i = 128; i > 0; i >>= 1)
  40. // Console.Write(((gray[50] & i) != 0) ? 1 : 0);
  41.  
  42. Console.WriteLine(Array.IndexOf<int>(gray, Convert.ToInt32("11111111", 2)));
  43. }
  44.  
  45. static List<char[]> piano(int n, int w)
  46. {
  47. List<char[]> res = new List<char[]>();
  48. if (w == 0)
  49. {
  50. char[] resc = new char[n];
  51. for (int i = 0; i < n; i++) resc[i] = '0';
  52. res.Add(resc);
  53. return res;
  54. }
  55. else if (w == 1)
  56. {
  57. char[] resc;
  58. for (int i = 0; i < n; i++)
  59. {
  60. resc = new char[n];
  61. for (int j = 0; j < n; j++) resc[j] = '0';
  62. resc[i] = '1';
  63. res.Add(resc);
  64. }
  65. return res;
  66. }
  67. else if (n == w)
  68. {
  69. char[] resc = new char[n];
  70. for (int i = 0; i < n; i++) resc[i] = '1';
  71. res.Add(resc);
  72. return res;
  73. }
  74. else
  75. {
  76. List<char[]> resl;
  77.  
  78. resl = piano(n - 1, w);
  79. foreach (char[] cs in resl)
  80. {
  81. char[] cx = (char[])cs.Clone();
  82. Array.Resize<char>(ref cx, n);
  83. cx[n - 1] = '0';
  84. res.Add(cx);
  85. }
  86.  
  87. resl = piano(n - 2, w - 1);
  88. resl.Reverse();
  89. foreach (char[] cs in resl)
  90. {
  91. char[] cx = (char[])cs.Clone();
  92. Array.Resize<char>(ref cx, n);
  93. cx[n - 2] = '0';
  94. cx[n - 1] = '1';
  95. res.Add(cx);
  96. }
  97.  
  98. resl = piano(n - 2, w - 2);
  99. foreach (char[] cs in resl)
  100. {
  101. char[] cx = (char[])cs.Clone();
  102. Array.Resize<char>(ref cx, n);
  103. cx[n - 2] = cx[n - 1] = '1';
  104. res.Add(cx);
  105. }
  106.  
  107. return res;
  108. }
  109. }
  110. }
  111. }
  112.  
Success #stdin #stdout 0.03s 38048KB
stdin
6
3
stdout
n=w=111000
110100
101100
011100
011010
101010
110010
100110
010110
001110
001101
100101
010101
011001
101001
110001
100011
010011
001011
000111