当前位置:网站首页>【暑期每日一题】洛谷 P1568 赛跑
【暑期每日一题】洛谷 P1568 赛跑
2022-07-01 04:47:00 【AC_Dragon】
题目链接:P1568 赛跑 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目背景
赛跑
题目描述
SH的跑步成绩一直不太理想。为了帮助SH提高成绩,KC决定和他进行一次赛跑。比赛的起点设在农场主的屋前,他们同时出发,沿着同一方向,直到跑到终点----农场远处的一棵树下。
他们的跑步速度在一些时间段内是恒定的。比如:SH在前3个时间段速度是5,接着6个时间段内速度是10。他们的比赛总时间相同。他们希望能统计出在整个比赛过程中领先顺序的变化次数。举个例子,某个时刻SH领先,下个时刻KC领先,这就是一次领先顺序的变化;如果某个时刻SH领先,接下来一段时间KC赶上来并和SH齐头并进,但最终还是超过了SH,这也是一次领先顺序的变化。
输入格式
第1行:N和M(1 <= N, M <= 1000)。
接下来的N行:每行两个整数,描述SH跑步的一段,分别表示该段SH跑步的速度和持续这种速度的时间。所有的数据范围 [1..1000]。
再接下来的M行:每行两个整数,描述KC跑步的一段,分别表示该段KC跑步的速度和持续这种速度的时间。所有的数据范围 [1..1000]。
输出格式
一行:整个比赛过程中领先顺序的变化次数。
样例 #1
样例输入 #1
4 3
1 2
4 1
1 1
2 10
2 3
1 2
3 9样例输出 #1
2提示
输入:SH在前2个单位时间内速度是1,接着1个单位时间内速度是4,接着1个单位时间内速度是1,最后10个单位时间内速度是2。KC在前3个个单位时间内速度是2,接着2个单位时间内速度是1,最后9个单位时间内速度是3。
输出:比赛开始后KC领先,直到第5个单位时间SH超过KC(第一次领先顺序变化),接着第7个单位时间时,KC又反超SH,变成领先(第二次领先顺序变化)。
AC code:(注意一定要开long long!!!)
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
typedef long long ll;
vector<ll> s1,s2;
ll n,m;
cin>>n>>m;
ll s=0;
while(n--)
{
ll a,b;
cin>>a>>b;
while(b--)
{
s+=a;
s1.push_back(s);
}
}
s=0;
while(m--)
{
ll a,b;
cin>>a>>b;
while(b--)
{
s+=a;
s2.push_back(s);
}
}
//i+1 1 2 3 4 5 6 7 8 9 10 11 12 13 14
//s1[i] 1 2 6 7 9 11 13 15 17 19 21 23 25 27
//s2[i] 2 4 6 7 8 11 14 17 20 23 26 29 32 35
//s2[i]-s1[i] 1 2 0 0 -1 0 1 2 3 4 5 6 7 8
ll cnt=0;
vector<ll> res;
for(ll i=0;i<s1.size();i++)
{
if(s1[i]!=s2[i]) // 路程差(s2[i]-s1[i])==0不放入
res.push_back(s2[i]-s1[i]);
}
for(ll i=1;i<res.size();i++)
if(res[i]*res[i-1]<0)
cnt++;
cout<<cnt;
return 0;
} 边栏推荐
- RuntimeError: mean(): input dtype should be either floating point or complex dtypes. Got Long instead
- Pytoch (II) -- activation function, loss function and its gradient
- 2022-02-15 (399. Division evaluation)
- Software testing needs more and more talents. Why do you still not want to take this path?
- Use and modification of prior network model
- Neural networks - use sequential to build neural networks
- 缓冲流与转换流
- [hard ten treasures] - 1 [basic knowledge] classification of power supply
- Basic skeleton of neural network nn Use of moudle
- 2022 polymerization process test questions and simulation test
猜你喜欢

最长递增子序列及最优解、动物总重量问题

Pytoch (II) -- activation function, loss function and its gradient

The longest increasing subsequence and its optimal solution, total animal weight problem

分布式-总结列表

Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and

pytorch中常用数据集的使用方法

LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target

RuntimeError: “max_pool2d“ not implemented for ‘Long‘

Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022

Openresty rewrites the location of 302
随机推荐
神经网络-最大池化的使用
Thoughts on the construction of Meizhou cell room
对象的序列化与反序列化
字符输入流与字符输出流
LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
先有网络模型的使用及修改
科研狗可能需要的一些工具
科研狗可能需要的一些工具
Shell之Unix运维常用命令
数据加载及预处理
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
JVM栈和堆简介
神经网络的基本骨架-nn.Moudle的使用
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
How to do the performance pressure test of "Health Code"
分布式-总结列表
How to view the changes and opportunities in the construction of smart cities?
All in all, the low code still needs to solve these four problems
洗个冷水澡吧
STM32扩展版 按键扫描