标签:
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\n",cnt); } return 0; }
标签:
原文地址:http://www.cnblogs.com/lcchuguo/p/4555134.html