B - JOE is on TV!
题目链接:http://codeforces.com/contest/1293/problem/B
思路:这题没咋看题,,,直接看了底下注释说是1/2+1/1,再看了两个样例,把数据往调和函数里一代就对了,,,直接暴力for循环求就行了
// // Created by HJYL on 2020/1/13. // #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #include<cmath> #define eps 1e-8 #define Inf 0x7fffffff //#include<bits/stdc++.h> using namespace std; const int maxn=1e5+100; struct Point{ double x,y; }; double min(double a, double b) { return a < b ? a : b; } double max(double a, double b) { return a > b ? a : b; } bool IsSegmentIntersect(Point a, Point b, Point c, Point d) { if( min(a.x, b.x) > max(c.x, d.x) || min(a.y, b.y) > max(c.y, d.y) || min(c.x, d.x) > max(a.x, b.x) || min(c.y, d.y) > max(a.y, b.y) ) return 0; double h, i, j, k; h = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x); i = (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x); j = (d.x - c.x) * (a.y - c.y) - (d.y - c.y) * (a.x - c.x); k = (d.x - c.x) * (b.y - c.y) - (d.y - c.y) * (b.x - c.x); return h * i <= eps && j * k <= eps; } int main() { int T; scanf("%d",&T); if(T==1) printf("1.000000000000 "); else { double sum=0.0; for(int i=1;i<=T;i++) { sum+=(1.0)/(i*1.0); } printf("%.12lf ",sum); } return 0; }