Skip to content

Instantly share code, notes, and snippets.

@kuuso
Created May 20, 2014 14:19
Show Gist options
  • Save kuuso/5ce0d932194bdd589f44 to your computer and use it in GitHub Desktop.
Save kuuso/5ce0d932194bdd589f44 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
class TEST{
static void Main(){
Sol mySol =new Sol();//コンストラクタ データ読み取り
mySol.Solve();
}
}
class Sol{
public Sol(){
Tours =new List<Ticket>();
String s="";
while((s=Console.ReadLine())!=null && s!=""){
//data input from stdin;
var ss=s.Split(" -/".ToCharArray());
Tours.Add(new Ticket(s,ss[0],100*int.Parse(ss[1])+int.Parse(ss[2]),100*int.Parse(ss[3])+int.Parse(ss[4])));
}
}
List<Ticket> Tours;
public void Solve(){
List<Ticket> Selection=new List<Ticket>();
int rest=Tours.Count;
int time=0;
//行ける目的地のうち最も早く帰ってくるものを選ぶ
// 行ける目的地をListに詰めてソート
//  (O(N)でいいのにO(NlogN)かけてしまっているorz)
while(rest>0){
List<Ticket> ToGo=new List<Ticket>();
rest=0;
for(int i=0;i<Tours.Count;i++){
if(Tours[i].Start>time)ToGo.Add(Tours[i]);
}
rest=ToGo.Count;
if(rest>0){
ToGo.Sort((x,y)=>x.End>y.End?1:(x.End<y.End?-1:0));
Selection.Add(ToGo[0]);
time=ToGo[0].End;
}
}
//answer write
Console.Write("{0}",Selection.Count);
Selection.Sort((x,y)=>String.Compare(x.Place,y.Place));
for(int i=0;i<Selection.Count;i++){
Console.Write(" {0}",Selection[i].Place);
}
Console.WriteLine("");
//detail write;
Console.WriteLine("");
Console.WriteLine("-- detail");
Selection.Sort((x,y)=>x.Start>y.Start?1:(x.Start<y.Start?-1:0));
for(int i=0;i<Selection.Count;i++){
Console.WriteLine("{0}\t{1}",i,Selection[i].Expr);
}
Console.WriteLine("");
}
}
struct Ticket{
public String Expr;
public String Place;
public int Start;
public int End;
public Ticket(String expr_,String place_,int start_,int end_){
this.Expr=expr_;
this.Place=place_;
this.Start=start_;
this.End=end_;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment