Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8.  
  9. namespace Naped
  10. {
  11. struct Vector
  12. {
  13. public int x, y, z;
  14.  
  15. public Vector(int x, int y, int z)
  16. {
  17. this.x = x;
  18. this.y = y;
  19. this.z = z;
  20. }
  21.  
  22. public static Vector operator -(Vector a, Vector b)
  23. {
  24. return new Vector(a.x - b.x, a.y - b.y, a.z - b.z);
  25. }
  26.  
  27. public static bool operator ==(Vector a, Vector b)
  28. {
  29. return a.x == b.x && a.y == b.y && a.z == b.z;
  30. }
  31.  
  32. public static bool operator !=(Vector a, Vector b)
  33. {
  34. return a.x != b.x || a.y != b.y || a.z != b.z;
  35. }
  36.  
  37. public bool IsNotNegative
  38. {
  39. get
  40. {
  41. return x >= 0 && y >= 0 && z >= 0;
  42. }
  43. }
  44. }
  45.  
  46. class Program
  47. {
  48. static public void Tick(Object stateInfo)
  49. {
  50. Console.WriteLine("Tick: {0}", DateTime.Now.ToString("h:mm:ss"));
  51. }
  52.  
  53. static void Main(string[] args)
  54. {
  55. TimerCallback callback = new TimerCallback(Tick);
  56.  
  57. int N;
  58. Vector[] V;
  59. using (TextReader reader = File.OpenText(@"..\..\..\in1.txt"))
  60. {
  61. N = int.Parse(reader.ReadLine());
  62. V = new Vector[N];
  63. for (int i = 0; i < N; i++)
  64. {
  65. int[] line = reader.ReadLine().Split(null).Select(x => int.Parse(x)).ToArray();
  66. V[i] = new Vector(line[0], line[1], line[2]);
  67. }
  68. }
  69. Console.WriteLine("Timer: {0}\n", DateTime.Now.ToString("h:mm:ss:ffffff"));
  70. int[,,] dp = new int[101, 101, 101];
  71. for (int i = 0; i < N; i++)
  72. {
  73. for (int x = 100; x >= 0; x--)
  74. {
  75. for (int y = 100; y >= 0; y--)
  76. {
  77. for (int z = 100; z >= 0; z--)
  78. {
  79. Vector a = new Vector(x, y, z); // aktualnie analizowany wektor
  80. Vector b = a - V[i]; // wektor potrzebny do otrzymania danej sumy
  81. if(a == V[i])
  82. {
  83. dp[a.x, a.y, a.z] = 1;
  84. }
  85. else if (b.IsNotNegative)
  86. {
  87. int aa = dp[a.x, a.y, a.z];
  88. int bb = dp[b.x, b.y, b.z];
  89. if(bb != 0)
  90. {
  91. dp[a.x, a.y, a.z] = aa == 0 ? bb + 1 : Math.Min(aa, bb + 1);
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
  98.  
  99. int maxSum, minCount;
  100. for (maxSum = 100; maxSum > 0 && dp[maxSum, maxSum, maxSum] == 0; maxSum--) ;
  101. minCount = dp[maxSum, maxSum, maxSum];
  102. maxSum *= 3;
  103. Console.WriteLine("Timer: {0}\n", DateTime.Now.ToString("h:mm:ss:ffffff"));
  104. Console.ReadKey();
  105. File.WriteAllText(@"..\..\..\out.txt", maxSum + " " + minCount);
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement