fork download
  1.  
  2. #include <bits/stdc++.h>
  3. #define lli long long int
  4. using namespace std;
  5.  
  6. /*
  7. Ways are something like this :
  8.  
  9. for number 10 :
  10.  
  11.   |--------O-2-O = 8
  12.   | \
  13.   | O-O-O-O-2-O = 4
  14.   | \
  15.   |--------O-O-O-O-O-O-O-2-O = 2
  16.   | \
  17.   | O-O-O-O-O-O-O-O-O-O- {Node 2} = 1
  18.  {Node 1}
  19.  
  20. */
  21.  
  22. bool ans[1005][1005];
  23.  
  24. int firstID[35];
  25. int lastID[35];
  26.  
  27. void createWays()
  28. {
  29. int startID[35];
  30.  
  31. int id = 3;
  32. for (int i=0,k=31 ; i<=31 ; i++,k--) // create bottom to up
  33. {
  34. firstID[i] = id; // set an id for first element in this row
  35.  
  36. for (int j=0 ; j<k ; j++) // create simple roads
  37. {
  38. ans[id][id+1] = ans[id+1][id+2] = 1;
  39. id+=2;
  40. }
  41.  
  42. startID[i] = id; // start of 2 way road
  43.  
  44. if (i!=0) // create 2 way road
  45. {
  46. ans[id][id+1] = ans[id][id+2] = 1;
  47. ans[id+1][id+3] = ans[id+2][id+3] = 1;
  48. id+=3;
  49. }
  50.  
  51. lastID[i] = id; // last of this row
  52.  
  53. if (i == 0)
  54. {
  55. ans[ lastID[i] ][ 2 ] = 1;
  56. }
  57. else
  58. {
  59. ans[ lastID[i] ][ startID[i-1] ] = 1;
  60. }
  61.  
  62. id++;
  63. cout<<id<<"\n";
  64. }
  65.  
  66.  
  67. for (int i=1 ; i<=1000 ; i++) // make symmetric
  68. for (int j=1 ; j<=1000 ; j++)
  69. ans[i][j] = ans[i][j] | ans[j][i];
  70. }
  71.  
  72. int main()
  73. {
  74. createWays();
  75.  
  76. int k;
  77. cin>>k;
  78.  
  79. int i=0;
  80. while (i<32)
  81. {
  82. if ( (1<<i) & k ) // connect
  83. {
  84. ans[1][ firstID[i] ] = 1;
  85. ans[ firstID[i] ][1] = 1;
  86. }
  87. i++;
  88. }
  89.  
  90. for (int i=1 ; i<=1000 ; i++)
  91. {
  92. for (int j=1 ; j<=1000 ; j++)
  93. {
  94.  
  95. }
  96. }
  97.  
  98. return 0;
  99. }
Runtime error #stdin #stdout 0s 4444KB
stdin
Standard input is empty
stdout
Standard output is empty