日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟

發布時間:2025/3/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

A. Gabriel and Caterpillar

題目連接:

http://www.codeforces.com/contest/652/problem/A

Description

The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2?>?h1) on the same tree hung an apple and the caterpillar was crawling to the apple.

Gabriel is interested when the caterpillar gets the apple. He noted that the caterpillar goes up by a cm per hour by day and slips down by b cm per hour by night.

In how many days Gabriel should return to the forest to see the caterpillar get the apple. You can consider that the day starts at 10 am and finishes at 10 pm. Gabriel's classes finish at 2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at 2 pm.

Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.

Input

The first line contains two integers h1,?h2 (1?≤?h1?<?h2?≤?105) — the heights of the position of the caterpillar and the apple in centimeters.

The second line contains two integers a,?b (1?≤?a,?b?≤?105) — the distance the caterpillar goes up by day and slips down by night, in centimeters per hour.

Output

Print the only integer k — the number of days Gabriel should wait to return to the forest and see the caterpillar getting the apple.

If the caterpillar can't get the apple print the only integer ?-?1

Sample Input

10 30
2 1

Sample Output

1

Hint

題意

有一個人,白天每小時爬a米,晚上每小時掉下來b米,可以掉到地下去

你從第0天的下午兩點看到這個人在h1,他要到h2去

早上10點到晚上十點算白天,其他算晚上

問你他第幾天到達h2

如果不能到達輸出-1

題解:

數學智障很慌,直接暴力模擬好了,啪啪啪就好了

代碼

#include<bits/stdc++.h> using namespace std;long long h1,h2,a,b; int main() {cin>>h1>>h2>>a>>b;int now = 14;int day = 0;int t = 0;while(t<1e7){t++;if(now>=10&&now<=21)h1+=a;else h1-=b;if(h1>=h2){cout<<day<<endl;return 0;}now=(now+1)%24;if(now==0)day++;}cout<<-1<<endl; }

轉載于:https://www.cnblogs.com/qscqesze/p/5327835.html

總結

以上是生活随笔為你收集整理的Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。