首页 > 代码库 > 玲珑杯 1137 - Sin your life(数学)

玲珑杯 1137 - Sin your life(数学)

题目链接:http://www.ifrog.cc/acm/problem/1137

 

题解:设m=n-z

sin(x)+sin(y)=sin(m-y)+sin(y)利用公式得最大值为sqrt(sin(m)*sin(m)+(1-cos(m))*(1-cos(m)))

所以只要便利一下z就可以了。

#include <iostream>#include <cstring>#include <cmath>#include <cstdio>#define Pi acos(-1)using namespace std;int main() {    int n;    scanf("%d" , &n);    double ans = 0 , Max = -3;    for(int i = 1 ; i <= n ; i++) {        int z = i;        int m = n - z;        Max = max(Max , sin(1.0 * z) + 1.0 * sqrt(sin(1.0 * m) * sin(1.0 * m) + (1.0 - cos(1.0 * m)) * (1.0 - cos(1.0 * m))));    }    printf("%.9lf\n" , Max);    return 0;}

玲珑杯 1137 - Sin your life(数学)