Skip to content

Instantly share code, notes, and snippets.

@mes51
Created April 29, 2013 08:43
Show Gist options
  • Save mes51/5480434 to your computer and use it in GitHub Desktop.
Save mes51/5480434 to your computer and use it in GitHub Desktop.
区間スケジューリング問題
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProgrammingContestChallenge.IntervalScheduling
{
class Program
{
private const string S = "1 2 4 6 8";
private const string T = "3 5 7 9 10";
static void Main(string[] args)
{
int[] s = S.Split(' ').Select(int.Parse).ToArray();
int[] t = T.Split(' ').Select(int.Parse).ToArray();
var lastWork = new { Start = -1, Finish = -1 };
var works = s.Zip(t, (start, finish) => new { Start = start, Finish = finish })
.OrderBy(x => x.Finish)
.Where(x => lastWork.Finish < x.Start ? (lastWork = x) != null : false).ToArray();
Console.WriteLine("count: " + works.Length.ToString());
Console.WriteLine("works:");
Console.WriteLine(string.Join(", \r\n", works.Select(x => x.ToString())));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment