zoukankan      html  css  js  c++  java
  • hdu 4803 贪心/思维题

    http://acm.hdu.edu.cn/showproblem.php?pid=4803

    话说C++还卡精度么?  G++  AC  C++ WA

    我自己的贪心策略错了 -- 就是尽量下键,然后上键,最后下键补全,可是例子都过不了.....

    题解參考http://www.cnblogs.com/xuesu/p/3967704.html

    http://www.cnblogs.com/Canon-CSU/p/3451784.html

    http://blog.csdn.net/keshuai19940722/article/details/26005267

    我还没理解透事实上o(╯□╰)o


    //#pragma comment(linker, "/STACK:102400000,102400000")
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <map>
    #include <set>
    #include <queue>
    using namespace std;
    
    #define ls(rt) rt*2
    #define rs(rt) rt*2+1
    #define ll long long
    #define ull unsigned long long
    #define rep(i,s,e) for(int i=s;i<e;i++)
    #define repe(i,s,e) for(int i=s;i<=e;i++)
    #define CL(a,b) memset(a,b,sizeof(a))
    #define IN(s) freopen(s,"r",stdin)
    #define OUT(s) freopen(s,"w",stdout)
    const ll ll_INF = ((ull)(-1))>>1;
    //const double EPS = 1e-8;
    const double pi = acos(-1.0);
    const int INF = 100000000;
    
    double p[11];
    
    void init()
    {
        p[0]=0;
        for(int i=1;i<=10;i++)
            p[i]=1+1.0/i;
        /////////////
        for(int i=0;i<11;i++)
            cout << "i= " << i << "  " << p[i] << endl;
    }
    
    const double EPS = 1e-9;///
    
    int main()
    {
        //IN("hdu4803.txt");
        int x,y;
        //init();
    
        while(~scanf("%d%d",&x,&y))
        {
            if(x>y){puts("-1");continue;}
            double k=(1.0*y+1-EPS)/x;
            int cnt=x-1;
            double ty=1;
            for(int i=1;i<=x;i++)
            {
                double t=i*k;
                int down=(int)(t-ty);
                ty+=down;
                cnt+=down;
                ty=ty*(i+1)/i;
            }
            printf("%d
    ",cnt);
    
        }
        return 0;
    }


  • 相关阅读:
    看代码所学1
    金额,重量,成绩不使用浮点数来表示,而使用整形
    安全风控的CAP原理和BASE思想
    Git操作
    项目上线规范以及一些词汇
    水滴筹面试
    Sping框架中的注解详解
    Restful技术
    @crossorigin注解跨域
    解决Ubuntu14.04下vi编辑器不能使用方向键和退格键问题
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4555134.html
Copyright © 2011-2022 走看看