Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace Naped
- {
- struct Vector
- {
- public int x, y, z;
- public Vector(int x, int y, int z)
- {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- public static Vector operator -(Vector a, Vector b)
- {
- return new Vector(a.x - b.x, a.y - b.y, a.z - b.z);
- }
- public static bool operator ==(Vector a, Vector b)
- {
- return a.x == b.x && a.y == b.y && a.z == b.z;
- }
- public static bool operator !=(Vector a, Vector b)
- {
- return a.x != b.x || a.y != b.y || a.z != b.z;
- }
- public bool IsNotNegative
- {
- get
- {
- return x >= 0 && y >= 0 && z >= 0;
- }
- }
- }
- class Program
- {
- static public void Tick(Object stateInfo)
- {
- Console.WriteLine("Tick: {0}", DateTime.Now.ToString("h:mm:ss"));
- }
- static void Main(string[] args)
- {
- TimerCallback callback = new TimerCallback(Tick);
- int N;
- Vector[] V;
- using (TextReader reader = File.OpenText(@"..\..\..\in1.txt"))
- {
- N = int.Parse(reader.ReadLine());
- V = new Vector[N];
- for (int i = 0; i < N; i++)
- {
- int[] line = reader.ReadLine().Split(null).Select(x => int.Parse(x)).ToArray();
- V[i] = new Vector(line[0], line[1], line[2]);
- }
- }
- Console.WriteLine("Timer: {0}\n", DateTime.Now.ToString("h:mm:ss:ffffff"));
- int[,,] dp = new int[101, 101, 101];
- for (int i = 0; i < N; i++)
- {
- for (int x = 100; x >= 0; x--)
- {
- for (int y = 100; y >= 0; y--)
- {
- for (int z = 100; z >= 0; z--)
- {
- Vector a = new Vector(x, y, z); // aktualnie analizowany wektor
- Vector b = a - V[i]; // wektor potrzebny do otrzymania danej sumy
- if(a == V[i])
- {
- dp[a.x, a.y, a.z] = 1;
- }
- else if (b.IsNotNegative)
- {
- int aa = dp[a.x, a.y, a.z];
- int bb = dp[b.x, b.y, b.z];
- if(bb != 0)
- {
- dp[a.x, a.y, a.z] = aa == 0 ? bb + 1 : Math.Min(aa, bb + 1);
- }
- }
- }
- }
- }
- }
- int maxSum, minCount;
- for (maxSum = 100; maxSum > 0 && dp[maxSum, maxSum, maxSum] == 0; maxSum--) ;
- minCount = dp[maxSum, maxSum, maxSum];
- maxSum *= 3;
- Console.WriteLine("Timer: {0}\n", DateTime.Now.ToString("h:mm:ss:ffffff"));
- Console.ReadKey();
- File.WriteAllText(@"..\..\..\out.txt", maxSum + " " + minCount);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement