跳到正文

题解

题解:P15521 [CCC 2016 J4] Arrival Time

gjr2025约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年3月6日
收录
2026年3月10日
更新
2026年11月14日
篇幅
约 1 分钟
题目
P15521

版本

  1. v1当前

题目描述

如果没有交通拥堵,通勤时间是 2 小时。高峰时段拥堵时,车速会减半。已知出发时间,何时能到达工作地点?

思路

可以理解为到工作地点的距离为 120120 个单位,高峰时段拥堵时可行驶 11 个单位,其余时段可行驶 22 个单位。因为速度和时间成反比,所以直接枚举 120120 个单位,高峰时段拥堵时需要 22 个单位时间行驶 11 个单位,其余时段需要 11 个单位时间行驶 11 个单位。用一开始的时间加上需要的时间即可。

AC Code

C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int a,b;
	char x;
	cin>>a>>x>>b;//可以直接输入一个字符,不需要string转int
	int t = a*60+b;
	for(int i=1;i<=120;++i){
		if((t >= 420 && t < 600) || (t >= 900 && t < 1140)) t+=2;//高峰时段拥堵时需要2个单位时间行驶1个单位
		else t++;//其余时段需要1个单位时间行驶1个单位
	}
	//cout<<t<<' ';
	if(t/60%24 < 10)cout<<0<<t/60%24<<':';
	else cout<<t/60%24<<':';
	if(t%60 < 10)cout<<0<<t%60;
	else cout<<t%60;
	return 0;
}
原文