Advertisement
sylviapsh

Academy Tasks (Niki's)

Jun 24th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.19 KB | None | 0 0
  1. namespace AcademyTasks
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     public class AcademyTasks
  7.     {
  8.         private static readonly List<int> tasks = new List<int>();
  9.         private static int variety;
  10.         private static int maxIndex;
  11.  
  12.         static void Main(string[] args)
  13.         {
  14.             string tasksAsStringLine = Console.ReadLine();
  15.             var tasksAsString = tasksAsStringLine.Split(new char[] { ',', ' ' },
  16.                 StringSplitOptions.RemoveEmptyEntries);
  17.             foreach (var taskAsString in tasksAsString)
  18.             {
  19.                 tasks.Add(int.Parse(taskAsString));
  20.             }
  21.  
  22.             variety = int.Parse(Console.ReadLine());
  23.  
  24.             Console.WriteLine(SolveWithDP());
  25.  
  26.             //bestSolution = tasks.Count;
  27.  
  28.             //int currentMin = tasks[0];
  29.             //int currentMax = tasks[0];
  30.             //maxIndex = -1;
  31.             //for (int i = 0; i < tasks.Count; i++)
  32.             //{
  33.             //    currentMin = Math.Min(currentMin, tasks[i]);
  34.             //    currentMax = Math.Max(currentMax, tasks[i]);
  35.             //    if (currentMax - currentMin >= variety)
  36.             //    {
  37.             //        maxIndex = i;
  38.             //        break;
  39.             //    }
  40.             //}
  41.  
  42.             //if (maxIndex == -1)
  43.             //{
  44.             //    Console.WriteLine(tasks.Count);
  45.             //    return;
  46.             //}
  47.  
  48.             //Solve(0, 1, tasks[0], tasks[0]);
  49.  
  50.             //Console.WriteLine(bestSolution);
  51.         }
  52.  
  53.         private static int SolveWithDP()
  54.         {
  55.             int minCount = tasks.Count;
  56.             for (int i = 0; i < tasks.Count - 1; i++)
  57.             {
  58.                 for (int j = i + 1; j < tasks.Count; j++)
  59.                 {
  60.                     if (Math.Abs(tasks[i] - tasks[j]) >= variety)
  61.                     {
  62.                         int count = 0;
  63.                         count += (i + 1) / 2; // from 0 to i, inclusive 0
  64.                         count += (j - i + 1) / 2 + 1; // from i to j, inclusive i and j
  65.                         minCount = Math.Min(minCount, count);
  66.                     }
  67.                 }
  68.             }
  69.             return minCount;
  70.         }
  71.  
  72.         //static int bestSolution;
  73.  
  74.         //static void Solve(int currentIndex, int taskSolved, int currentMin, int currentMax)
  75.         //{
  76.         //    if (currentMax - currentMin >= variety)
  77.         //    {
  78.         //        bestSolution = Math.Min(bestSolution, taskSolved);
  79.         //        return;
  80.         //    }
  81.  
  82.         //    if (currentIndex >= maxIndex)
  83.         //    {
  84.         //        return;
  85.         //    }
  86.  
  87.         //    for (int i = 2; i >= 1; i--)
  88.         //    {
  89.         //        if (currentIndex + i < tasks.Count)
  90.         //        {
  91.         //            Solve(currentIndex + i, taskSolved + 1,
  92.         //                Math.Min(currentMin, tasks[currentIndex + i]),
  93.         //                Math.Max(currentMax, tasks[currentIndex + i]));
  94.  
  95.         //            if (bestSolution != tasks.Count)
  96.         //            {
  97.         //                return;
  98.         //            }
  99.         //        }
  100.         //    }
  101.         //}
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement