A. Gabriel and Caterpillar(cf)
来源:互联网 发布:网络情感诈骗的方法 编辑:程序博客网 时间:2024/05/21 17:49
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 heighth1 cm from the ground. On the heighth2 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 bya cm per hour by day and slips down byb 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 at10 am and finishes at10 pm. Gabriel's classes finish at2 pm. You can consider that Gabriel noticed the caterpillar just after the classes at2 pm.
Note that the forest is magic so the caterpillar can slip down under the ground and then lift to the apple.
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.
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.
10 302 1
1
10 131 1
0
10 191 2
-1
1 505 4
1
In the first example at 10 pm of the first day the caterpillar gets the height26. At10 am of the next day it slips down to the height14. And finally at6 pm of the same day the caterpillar gets the apple.
Note that in the last example the caterpillar was slipping down under the ground and getting the apple on the next day.
AC代码
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int h1, h2, a, b, day = 0;
scanf("%d%d%d%d", &h1, &h2, &a, &b);
h1 += a*8;
if( h1>=h2 )
printf("0\n");
else
{
day++;
while(1)
{
h1 -= b*12;
h1 += a*12;
if( h1>=h2 )
{
printf("%d\n", day);
break;
}
if( b>=a )
{
printf("-1\n");
break;
}
day++;
}
}
return 0;
}
终于知道为什么说我思路不清晰了,囧死
- A. Gabriel and Caterpillar(cf)
- codeforce-A. Gabriel and Caterpillar(模拟)
- codeforces--652A Gabriel and Caterpillar (模拟)
- codeforces 652 A. Gabriel and Caterpillar
- Code Forces 652A Gabriel and Caterpillar
- Codeforces 652A Gabriel and Caterpillar【水题】
- 【CodeForces】[652A]Gabriel and Caterpillar
- Codeforces 652A Gabriel and Caterpillar (此题有毒)
- CodeForces 652A Gabriel and Caterpillar(模拟)
- Codeforces Round 10 A. Gabriel and Caterpillar 模拟
- Codeforces 652A Gabriel and Caterpillar(毛毛虫摘苹果)
- 【Codeforces 652 A Gabriel and Caterpillar】+ 手速
- CodeForces 652 A.Gabriel and Caterpillar(水~)
- 【Educational Codeforces Round 10A】【简单讨论】Gabriel and Caterpillar 白天爬a晚上落b多久爬出洞
- (CF)A. Vanya and Cards
- cf,A. Mashmokh and Lights
- cf 760A Petr and a calendar
- codeforces652AGabriel and Caterpillar(模拟题)
- 发个手机全息投影(制作方法已放出,补上世界第一公主)
- 线性判别分析(Linear Discriminant Analysis)(一)
- 动态规划经典联系题----找零钱
- POI操作Excel常用方法总结
- 线性判别分析(Linear Discriminant Analysis)(二)
- A. Gabriel and Caterpillar(cf)
- 第五周总结
- 线程锁的概念函数EnterCriticalSection和LeaveCriticalSection的用法
- stl: map和hashmap比较 hashmap与hashtable
- struts 下载地址
- 我的Exchange 2010 启用匿名了。我怎么防止别人任意伪造一个邮件地址发送给我内部的人呢?
- 人生的一种境界:享受第四种感情
- jQuery源码解析(2)—— Callback、Deferred异步编程
- Maven入门