注册 登录
编程论坛 数据结构与算法

杭电1048题,求解答错误的地方!谢谢!

daemon1 发布于 2011-09-04 17:54, 718 次点击
#include <iostream>
using namespace std;
int main()
{
    double n,m;
    while(cin>>n>>m)
    {
        double cnt_all=n;                   //总盐水升数
        __int64  cnt_time=0;               //计算总时间
        int cnt=1;                         //计算每一秒间隔后的连续滴盐水数量
        while(1)
        {
            double a=cnt_all;
            cnt_all=cnt_all-cnt*m;            
            cnt_time=cnt_time+cnt;           
            if(cnt_all<=0)                 //如果cnt_all<=0则剩下的盐水将在连续滴中滴完
            {
                if(cnt_all<0)
                {
                    int i=0;
                    while(a>0)
                    {
                        a-=m;
                        i++;
                    }
                    cnt_time=cnt_time-cnt+i;  //计算出刚好滴完的时候
                }
                printf("%I64d\n",cnt_time);
                break;
            }
            cnt++;
            cnt_time++;
        }
    }
    return 0;
}
4 回复
#2
daemon12011-09-05 17:06
无人??
#3
编程的乐趣2011-09-05 20:51
c++用printf,虽然可以,但挺乱
1