跳到正文

题解

题解:P15545 「Stoi2037」晴天

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

文章信息

发布
2026年3月1日
收录
2026年3月2日
更新
2026年11月15日
篇幅
约 1 分钟
题目
P15545

版本

  1. v1当前

萌新题qwq。

遍历每一天的天气值,计算当天能走的路程并累加,只要累计路程 ≥s≥s,答案就是当前天数;若遍历完所有天数仍未达标,输出-1即可。

Code
C++
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n,s,x,a=-1,d,t=0;
    cin>>n>>s>>x;
    for(int i=0;i<n;i++){
        cin>>d;
        int k=(d==0? x:(d==-1? 0:x-d));
        t+=k;
        if(t>=s && (i==0 || t-k<s)){
            a=i+1;
            break;
        }
    }
    cout<<a;
    return 0;
}

希望这些能帮助到你们!

原文
存档评论1 条抓取于