当前位置:网站首页>【暑期每日一題】洛穀 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;
} 边栏推荐
- Pytorch(二) —— 激活函数、损失函数及其梯度
- Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
- RuntimeError: mean(): input dtype should be either floating point or complex dtypes. Got Long instead
- 扩展-Fragment
- Solve the problem that the external chain file of Qiankun sub application cannot be obtained
- How to view the changes and opportunities in the construction of smart cities?
- Difficulties in the development of knowledge map & the importance of building industry knowledge map
- Shell之分析服务器日志命令集锦
- 无器械健身
- 【FTP】FTP常用命令,持续更新中……
猜你喜欢

CF1638E. Colorful operations Kodori tree + differential tree array

pytorch 卷积操作

Pytorch(四) —— 可视化工具 Visdom

Pytorch convolution operation

STM32 extended key scan

Pytoch (I) -- basic grammar

Common methods in transforms

Extension fragment
![解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *](/img/88/0b99d1db2cdc70ab72d2b3c623dfaa.jpg)
解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *

Neural networks - use of maximum pooling
随机推荐
Basic usage, principle and details of session
STM32 光敏电阻传感器&两路AD采集
C -- array
Pytorch(三) —— 函数优化
STM32 photoresistor sensor & two channel AD acquisition
分布式架构系统拆分原则、需求、微服务拆分步骤
Software testing needs more and more talents. Why do you still not want to take this path?
线程类的几大创建方法
[hardware ten treasures catalogue] - reprinted from "hardware 100000 whys" (under continuous update ~ ~)
VR线上展览所具备应用及特色
对象的序列化与反序列化
Cmake selecting compilers and setting compiler options
Common methods in transforms
【硬十宝典】——1.【基础知识】电源的分类
Basic exercise of test questions hexadecimal to decimal
2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
2022 hoisting machinery command registration examination and hoisting machinery command examination registration
Data loading and preprocessing
Applications and features of VR online exhibition