【贪心专题】HDU 1049 Climbing Worm (爬井趣题)

链接:click here~~

题意:

题目大致意思是一个虫子掉在了一个n长度深的井中,然后它每分钟可以爬u长度,然后要休息一分钟,在此期间它会掉下d长度,问最终爬出井需要多久。

简单模拟:

代码:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a,b,c,i,j;
    while(~scanf("%d%d%d",&a,&b,&c)&&a&&b&&c)
    {
        int i=0,s=0;
        for(;;){
            s+=b,i++;
            if(s>=a){
                printf("%d\n",i);
                break;
            }
            s-=c,i++;
            if(s>=a){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}
时间: 2024-08-08 09:37:24

【贪心专题】HDU 1049 Climbing Worm (爬井趣题)的相关文章

HDU 1049.Climbing Worm【水!水!水!】【8月25】

Climbing Worm Problem Description An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of

hdu 1049 Climbing Worm

Problem Description An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of climbing and

NYOJ 1049 Climbing Worm

Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12116    Accepted Submission(s): 8149 Problem Description An inch worm is at the bottom of a well n inches deep. It has enough ener

HDOJ 1049 Climbing Worm

Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12116    Accepted Submission(s): 8149 Problem Description An inch worm is at the bottom of a well n inches deep. It has enough ener

【贪心专题】HDU 1009 FatMouse&#39; Trade (贪心选取)

链接:click here~~ 题意:老鼠准备了M磅猫食,准备拿这些猫食跟猫交换自己喜欢的食物.有N个房间,每个房间里面都有食物.你可以得到J[i]单位的食物,但你需要付出F[i]单位的的猫食. 计算M磅猫食可以获得最多食物的重量. [解题思路]贪心算法,求最优解.将J[i]/F[i]的值从大到小排列,每次取最大的,局部最优,达到全局最优,从而获得最大值. 代码: // 贪心策略,优先选择投资最大的房间,每选择一次,交换次数依次减少,最后的次数用于价值最小的 //注意精度转化:1.0*(int

杭电OJ(HDU)-ACM Steps-Chapter Two-《Biker&#39;s Trip Odometer》《Climbing Worm》《hide handkerchief》《Nasty Hac》

1.2.1 Biker's Trip Odometer #include<stdio.h> #include<math.h> const double PI=acos(-1.0); /* 计算题,根据公式做就行,PI*d*r/(12*5280);res1/t*3600; Sample Input 26 1000 5 27.25 873234 3000 26 0 1000 Sample Output Trip #1: 1.29 928.20 Trip #2: 1179.86 1415

贪心专题

贪心: 原则是根据固定的一个或几个属性进行抉择.达到缩小规模的目的. split to steps and shrink scope 有点双端/DAG图的意思. reference 最近做的几个贪心题目 hdu 1052(田忌赛马) 根据马的速度排序,然后两边最小值,最大值的判断.这样做是因为两端的选择是唯一的,TJ最弱的马/最强的如果可以战胜那就是最好的抉择,不然就让其去当炮灰.(减少规模) #include<set> #include<cmath> #include<cs

16.10.20 4th 1蛤蟆爬井 2一维数组 3二维数组

摘要 1蛤蟆爬井 2一维数组 3二维数组 例子 井深10米, 蛤蟆白天爬5m,晚上落4米,求几天爬出来. //思路,用循环语句来做,for因为是未知次数所以排除,while 先判断后运行排除, dowhile,先爬在判断所以可以 int gaodu = 0; int tianshu = 0; boolean tianse = true; do{ if(tainse){ //白天爬5米 gaodu+=5; //爬完后改黑天 tianse = false; //天数+1 tianshu +=1; }

[CareerCup] 9.1 Climbing Staircase 爬楼梯

9.1 A child is running up a staircase with n steps, and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs. LeetCode上的原题,请参见我之前的博客Climbing Stairs 爬梯子问题. class Solut