codeforcesとかcygwinとか

今日は英語の論文発表だったので、とある場所に向かいました。
そこで取った昼食のオムハヤシ大盛りがこれ。

codeforcesとかcygwinとか_f0019846_1391429.jpg


400円。まあ妥当って感じでしょうか。

その後、友人からこんなものもらいました。

codeforcesとかcygwinとか_f0019846_1395571.jpg


codeforcesとかcygwinとか_f0019846_1401724.jpg


うん、まあ、ノーコメントでいきましょうか。

そして帰路につくまえにゲーセンに行ったんですが、
人大杉でなんだろうと思ったら祝日だということをすっかり忘れていました。
誰もやっていないpop'nを1クレやって早々に退散しました。

帰宅後は運動してcodeforcesの準備。
1問目にとりかかるも、見事に時間がかかってもうまくいかず。
2問目を見ても意味不明なので1問目に戻り、結局2時間で何も解けませんでした。
という訳で- - - - - です。
そしてどうやら今回Div2とDiv1が共通だったようで。
そりゃあ難しいもんだと。

取り敢えず1問目がどんな問題か、把握するのに15分かかりましたが、
一応説明しましょう。

エレベーターはある階層まで上がる。これをnとする
エレベーターは時刻0で1Fにある。時刻1進むごとに1ずつ上がる。
最上階まで上がったら今度は1つずつ降りて1F迄戻る繰り返し。
つまり
1 2 3 4 5 6 7 ・・・ n n-1 n-2 ・・・ 3 2 1 ということです。

客がn人いて、i番目の客は、時刻t[i]にa[i]階にいて、b[i]階に行きたい。
timeはいくつになるか。

例えば5Fまでのエレベーターがあるとして、
ある人が3Fから4Fにいきたいとする。時間は3。
つまり 3 4 3というデータが与えられる。
ちなみに時刻3のときは、 1 2 3 4 とエレベーターは4Fにあり、さらに上がろうとしているところ。
降りてくるけど、降りのエレベーターに乗ってもダメなので、再度上がってくるまで待たなきゃいけない。
1 2 3 4 5 4 3 2 1 2 3 でようやくのれる。
そして最後に4になれば終了。
つまり 1 2 3 4 5 4 3 2 1 2 3 4となり、時刻は11という結果になる。

ちなみに同じ階層に行こうとしてる奴は、エレベーターに乗らなくていいので、timeそのまんまを返せばokです。

マグロたたき丼を食べた後に、頑張ってみました。

codeforcesとかcygwinとか_f0019846_1404787.jpg


import java.util.*;

public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int person = input.nextInt();
int floor = input.nextInt();
int[] start = new int[person];
int[] end = new int[person];
int[] time = new int[person];
for(int i = 0 ; i < person ; i++){
start[i] = input.nextInt();
end[i] = input.nextInt();
time[i] = input.nextInt();
}

for(int i = 0 ; i < person ; i++){
System.out.println(timeArrive(person,floor,start[i],end[i],time[i]));
}



}

public static int timeArrive(int person,int floor, int start,int end,int time){
int restart = floor-start;
int timecurrent = time/(floor-1);

//If people at the same floor.
if(start == end){
return time;
}

if(timecurrent % 2 == 1){//If elevator is descenting now.
if(time % (floor-1) <= restart){//If elevator is going to come.
if(end <= start){//If people want to descent floor.
time += (restart - (time % (floor-1)));
return time+(start-end);
}else{//If people want to ascent floor.
time += (floor - (time % (floor-1)+1));
return (time+end-1);
}
}else{//If elevator passed floor.
time += (floor - (time % (floor-1)+1));
if(start <= end){//If people want to ascent floor.
time += (end-1);
return time;
}else{//If people want to descent floor.
time += (floor-1);
return time+(floor-end);
}
}
}else if(timecurrent % 2 == 0){//If elevator is ascenting now.
if(time % (floor-1)+1 <= start){//If elevator is going to come.
if(end >= start){//If people want to ascent floor.
time += (start - (time % (floor-1)+1));
return time+end-start;
}else{//If people want to descent floor.
time += (floor - (time % (floor-1)+1));
time += (floor-end);
return time;
}
}else{//If elevator passed floor.
time += (floor - (time % (floor-1)+1));
if(start >= end){//If people want to descent floor.
time += (floor-end);
return time;
}else{//If people want to ascent floor.
time += (floor-1);
time += end-1;
return time;
}
}
}
return -1;//This statement mustn't come.
}

真面目に書いたけど条件分岐多すぎですね。
もっと簡潔に書く方法はありそうです。

そして、朝にcygwinのインストールをしましたが、自宅pcではあっさりだったのに、
atomのPCでは7時間かかるという憂き目に遭いました。

  by ddrer-yossi | 2011-09-23 23:33 | codeforces

<< 絶品な海鮮丼 ゲーセン廃人はよくない >>

SEM SKIN - DESIGN by SEM EXE