zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 10 A. Gabriel and Caterpillar

    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    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.
    Examples
    Input
    Copy
    10 30
    2 1
    Output
    Copy
    1
    Input
    Copy
    10 13
    1 1
    Output
    Copy
    0
    Input
    Copy
    10 19
    1 2
    Output
    Copy
    -1
    Input
    Copy
    1 50
    5 4
    Output
    Copy
    1
    Note
    In the first example at 10 pm of the first day the caterpillar gets the height 26. At 10 am of the next day it slips down to the height 14. And finally at 6 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.

    题解:sb题,有个细节就是毛毛虫是可以滑倒地底下了,under the ground,然而我刚开始理解是滑倒地上后直接升到苹果上,这就是魔法森林的由来.哈哈,带着这个想法看样例,发现不对,然后又理解成就是到地上后就停了,但是这又和魔法森林没关系,如果我当时带着这样的想法再去看题就不wa这么多次了,欸长记性了,一旦卡太久就跳过,别死磕着,wa太多次一定要看看原题,

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
    	int h1,h2,a,b;
    	scanf("%d%d%d%d",&h1,&h2,&a,&b);
    	if(a*8+h1>=h2){
    		printf("0
    ");
    		return 0;
    	}
    	int ans=0;
    	h1+=a*8;
    	if(a<=b){
    		printf("-1
    ");
    		return 0;
    	}
    	else{
    		while(h1<h2){
    			//if(b*12>=h1) h1=0;
    			h1=h1-b*12;
    			h1+=a*12;
    			ans++;
    		}
    	}
    	printf("%d
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    虚基类练习 动物1
    UVa 10820
    hdu1027 Ignatius and the Princess II (全排列 &amp; STL中的神器)
    在windows下安装redmine及相关问题
    批量导出表数据到CSV文件
    轻松学习Ionic (二) 为Android项目集成Crosswalk(更新官方命令行工具)
    swift第一章
    socket编程演示样例(多线程)
    谋哥:玩App怎么赚钱(三)
    Oracle database wrc运行报错ORA-15557
  • 原文地址:https://www.cnblogs.com/-yjun/p/10424228.html
Copyright © 2011-2022 走看看