[USACO 2014 Jan Silver]Bessie Slows Down

14 篇文章 0 订阅

再一次颓废。。

[题目描述]

Bessie正在Sczolympics冬季运动会上参加滑雪项目。她以1m/s的速度开始。但是,随着时间推移,她越来越劳累,她的速度也开始下降。每当Bessie减速时,第一次减速后她以1/2 m/s的速度滑行,第二次减速后以1/3 m/s的速度滑行,以此类推。

将有一系列的事件,你会被告知Bessie是在哪时候速度下降的。比如这样:

T 17 :表示Bessie在某一特定时间减速。如此处,便是在18秒的时候减速。

D 10 :表示Bessie在某一特定距离减速。如此处,便是在10米处减速。

给出N(1<=N<=10,000)个事件,请按秒为单位计算出Bessie滑完1km所需要的时间。并将你的答案四舍五入到整数输出。


傻逼模拟,对D和T排序,然后判断下一次是D还是T

const shuru='slowdown.in';
	  shuchu='slowdown.out';
	  maxn=10001;
var	t,d:array[0..maxn] of longint;
	p,tot1,tot2,i,j,k,n,count1,count2:longint;
	count,t1,t2,nowv,nowd,nowt:extended;
	ch:char;
procedure init;
begin
	readln(n);
	for i:=1 to n do
	begin
		read(ch);
		case ch of	
			'D':begin
					inc(count1);
					read(d[count1]);
				end;
			'T':begin
					inc(count2);
					read(t[count2]);
				end;
		end;
		readln;
	end;
end;
procedure qsort(left,right:longint);
var i,j,mid:longint;
begin
	i:=left; j:=right; mid:=d[(i+j) shr 1];
	repeat
		while d[i]<mid do inc(i);
		while d[j]>mid do dec(j);
		if i<=j then begin
						p:=d[i]; d[i]:=d[j]; d[j]:=p;
						inc(i); dec(j);
					 end;
	until i>j;
	if j>left  then qsort(left,j);
	if i<right then qsort(i,right);
end;
procedure qsort1(left,right:longint);
var i,j,mid:longint;
begin
	i:=left; j:=right; mid:=t[(i+j) shr 1];
	repeat
		while t[i]<mid do inc(i);
		while t[j]>mid do dec(j);
		if i<=j then begin
						p:=t[i]; t[i]:=t[j]; t[j]:=p;
						inc(i); dec(j);
					 end;
	until i>j;
	if j>left  then qsort1(left,j);
	if i<right then qsort1(i,right);
end;
function equal(a,b:extended):boolean;
begin
	if abs(a-b)<0.00001 then exit(true);
	exit(false);
end;
procedure main;
begin
	init;
	qsort(1,count1);
	qsort1(1,count2);
	t[count2+1]:=maxlongint;
	d[count1+1]:=maxlongint;
	i:=0; j:=0; nowv:=1; nowd:=0; nowt:=0; count:=1;
	while not((i=count1) and (j=count2)) do
	begin
		t1:=(d[i+1]-nowd)*count;
		t2:=t[j+1]-nowt;
		if equal(t1,t2) then begin
								inc(i); inc(j);
								count:=count+2;
								while d[i+1]=d[i] do begin count:=count+1; inc(i); end;
								while t[j+1]=t[j] do begin count:=count+1; inc(j); end;
								nowt:=t[j];
								nowd:=d[i];
								continue;
							 end;
		if t1>t2 then begin
						inc(j);
						nowt:=t[j];
						nowd:=nowd+t2*(1/count);
						count:=count+1;
						while t[j+1]=t[j] do begin inc(j); count:=count+1; end;
						continue;
					  end;
		if t2>t1 then begin
						inc(i);
						nowd:=d[i];
						nowt:=nowt+t1;
						count:=count+1;
						while d[i+1]=d[i] do begin inc(i); count:=count+1; end;
					  end;
	end;
	writeln((nowt+(1000-nowd)*count):0:0);
end;
begin
	main;
end.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值