跳到正文

题解

题解:P15545 「Stoi2037」晴天

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

文章信息

发布
2026年3月1日
收录
2026年8月18日
更新
2026年11月13日
篇幅
约 1 分钟
获赞
1
题目
P15545

版本

  1. v1当前

P15545 「Stoi2037」晴天 题解

思路

模拟行走情形,若没到达则继续,到达后用变量保存天数。

代码

C++
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long n,s,v;//变量
	cin>>n>>s>>v;//输入
	long long l=0,t=-1;//l 行走路程
	for(int i=1;i<=n;i++){
		int p;
		cin>>p;
		if(p==-1)//不能走
			continue;
		else//能走(p=0算作风速为0)
			l+=v-p;
		if(l>=s&&t==-1)//到达B城
			t=i;
	}
	cout<<t;//输出
	return 0;//完美
}
原文