标签:space from 直接 思维 pst get which win none
题目链接:http://poj.org/problem?id=1759
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 2477 | Accepted: 1054 |
Description
Input
Output
Sample Input
692 532.81
Sample Output
446113.34
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <vector> 6 #include <cmath> 7 #include <queue> 8 #include <stack> 9 #include <map> 10 #include <string> 11 #include <set> 12 #define rep(i,a,n) for(int (i) = a; (i)<=(n); (i)++) 13 #define ms(a,b) memset((a),(b),sizeof((a))) 14 using namespace std; 15 typedef long long LL; 16 const double EPS = 1e-8; 17 const int INF = 2e9; 18 const LL LNF = 9e18; 19 const int mod = 1e9+7; 20 const int maxn = 1e5+10; 21 22 int n; 23 double A, ans; 24 25 bool test(double x1, double x2) 26 { 27 for(int i = 3; i<=n; i++) //递推出每个点的高度 28 { 29 double x3 = 2*x2+2-x1; 30 if(x3<=0) return false; //出现负数,证明接地了, 不符合。 31 x1 = x2, x2 = x3; 32 } 33 ans = x2; //符合条件, 则更新答案。 34 return true; 35 } 36 37 int main() 38 { 39 while(scanf("%d%lf", &n, &A)!=EOF) 40 { 41 double l = 0, r = A; //二分第二个点 42 while(l+EPS<=r) 43 { 44 double mid = (l+r)/2; 45 if(test(A, mid)) 46 r = mid - EPS; 47 else 48 l = mid + EPS; 49 } 50 printf("%.2f\n", ans); 51 } 52 }
标签:space from 直接 思维 pst get which win none
原文地址:http://www.cnblogs.com/DOLFAMINGO/p/7586738.html