http://www.ifrog.cc/acm/problem/1137

和差化积公式,

变成2 * sin((x + y) / 2) * cos((x - y) / 2) + sin(n - (x + y))

然后很重要的一个就是cos(x) = cos(-x)

这样,枚举x + y的取值i,当x + y取值是i的时候,x - y的取值也是有固定的规律,具体就是

i是偶数的时候,0、2、...、这样吧

i是奇数的时候,1、3......、这样吧

然后就要分情况取值,

当sin((x + y) / 2)小于0,就要取一个min去和它乘,否则娶个大的,

数组开大了TLE,不是很懂。

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
double dp[][];
void work() {
int n;
scanf("%d", &n);
dp[][] = dp[][] = ;
dp[][] = dp[][] = cos(0.5);
double ans = -1.0;
for (int i = ; i <= n - ; ++i) {
double res = sin(i * 0.5);
if (res < ) {
if (i & ) {
ans = max(ans, * res * dp[][] + sin(n - i));
} else ans = max(ans, * res * dp[][] + sin(n - i));
} else {
if (i & ) {
ans = max(ans, * res * dp[][] + sin(n - i));
} else ans = max(ans, * res * dp[][] + sin(n - i));
}
res = cos(i);
dp[][] = min(dp[][], res);
dp[][] = max(dp[][], res);
dp[][] = min(dp[][], res);
dp[][] = max(dp[][], res);
}
printf("%0.9f\n", ans);
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 3e6 + ;
double dp[maxn][];
void work() {
int n;
scanf("%d", &n);
dp[][] = dp[][] = cos();
dp[][] = dp[][] = cos(0.5);
// for (int i = 2; i <= n; ++i) {
// dp[i][0] = min(dp[i - 2][0], cos(i * 0.5));
// dp[i][1] = max(dp[i - 2][1], cos(i * 0.5));
// }
double ans = -1.0;
for (int i = ; i <= n - ; ++i) {
double res = sin(i * 0.5);
if (i & ) {
ans = max(ans, * res * dp[i - ][] + sin(n - i));
} else {
ans = max(ans, * res * dp[i - ][] + sin(n - i));
}
res = cos(i * 0.5);
dp[i][] = min(dp[i - ][], res);
dp[i][] = max(dp[i - ][], res);
}
printf("%0.9f\n", ans);
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

TLE code

1137 - Sin your life sin公式 + 枚举的更多相关文章

  1. [再寄小读者之数学篇](2014-11-19 $\sin(x+y)=\sin x\cos y+\cos x\sin y$)

    $$\bex \sin(x+y)=\sin x\cos y+\cos x\sin y. \eex$$ Ref. [Proof Without Words: Sine Sum Identity, The ...

  2. sin n次方 x 的降幂公式

    A(n) = ∫ sinⁿx dx= ∫ sinⁿ⁻¹xsinx dx= - ∫ sinⁿ⁻¹x d(cosx)= - sinⁿ⁻¹xcosx + ∫ cosx • d(sinⁿ⁻¹)= - sinⁿ ...

  3. 数学中的Sin和Cos是什么意思?(转)

    数学中的Sin和Cos是什么意思? 作者:admin 分类:生活随笔 发表于 2012年03月21日 16:48 问:数学中的Sin和Cos是什么意思? 答:sin, cos, tan 都是三角函数, ...

  4. 利用Xilinx中的ROM构造查找表来计算sin和cos的方法探讨

    1.使用matlab制作.coe文件 查找表的构造 构造256点的正余弦表 exp(-j*2*pi*(0:255)/256),分别得到 cos和sin的查找表 matlab代码: 求sin fid = ...

  5. 数学图形(1.2)Sin曲线

    相关软件参见:数学图形可视化工具,使用自己定义语法的脚本代码生成数学图形.该软件免费开源.QQ交流群: 367752815 Sin曲线 vertices = x = *PI) to (*PI) y = ...

  6. Python sin() 函数

    描述 sin() 返回的x弧度的正弦值. 语法 以下是 sin() 方法的语法: import math math.sin(x) 注意:sin()是不能直接访问的,需要导入 math 模块,然后通过 ...

  7. 带 sin, cos 的线段树 - 牛客

    链接:https://www.nowcoder.com/acm/contest/160/D来源:牛客网 题目描述给出一个长度为n的整数序列a1,a2,...,an,进行m次操作,操作分为两类.操作1: ...

  8. sin之舞---蓝桥杯练习

    问题描述 最近FJ为他的奶牛们开设了数学分析课,FJ知道若要学好这门课,必须有一个好的三角函数基本功.所以他准备和奶牛们做一个“Sine之舞”的游戏,寓教于乐,提高奶牛们的计算能力. 不妨设 An=s ...

  9. 已知三角形ABC为锐角三角形,求 sinA + sinB·sin(C/2) 的最大值。

    已知三角形ABC为锐角三角形,求 sinA + sinBsin(C/2) 的最大值. 解:Δ := sinA + sinB·sin(C/2) = sin(B+C) + sinB·sin(C/2) = ...

随机推荐

  1. hdu-5780 gcd(数学)

    题目链接: gcd Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others) Pro ...

  2. AtCoder AGC #4 Virtual Participation

    我好懒啊QAQ 老规矩 从C开始 C.给一个矩阵,里面有一些紫色方块,你需要涂两个矩阵,一个红色,一个蓝色,保证你涂的颜色四连通 然后把红色蓝色矩阵叠起来要求紫色的地方必须是紫色,其他地方不能是紫色 ...

  3. bjwc Day2 玄学

    早晨起来很开心,因为昨天跟妹子聊天聊到很晚 然后看到了题,感觉:这tm才是冬令营呀! T1构造,并没有找到性质,暴力都懒得打 T2数位dp,状态比较麻烦,看来跟dmy想到一起了,然后搞一下搞完 T3放 ...

  4. 查询oracle 数据库 SQL语句执行情况

    1.查看总消耗时间最多的前10条SQL语句 select *  from (select v.sql_id,  v.child_number,  v.sql_text,  v.elapsed_time ...

  5. 用CSS实现新闻轮播效果

    CSS: /* Make it a marquee */ .marquee { width: 450px;margin: 0 auto;overflow: hidden;white-space: no ...

  6. 【Opencv】直方图函数 calchist()

    calchist函数需要包含头文件 #include <opencv2/imgproc/imgproc.hpp> 函数声明(三个重载 calchist函数): //! computes t ...

  7. QT(1)介绍

    Qt官网 Qt官网:https://www.qt.io Qt下载:http://www.qt.io/download Qt所有下载:http://download.qt.io/archive/qt Q ...

  8. 2012年浙大:Hello World for U

    题目描述: Given any string of N (>=5) characters, you are asked to form the characters into the shape ...

  9. Python之模块介绍

    模块介绍 模块,是用一些代码实现的某个功能的代码集合. 类似与函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用,提供了代码的重用性和代码间的耦合.对于一个复杂的功能,可能需要多个函 ...

  10. Crypto Challenge Set 1解题报告

    1.Convert hex to base64 题意:给出一个hex编码过的字符串,将它进行base64加密 解题关键:直接利用base64库函数实现 import base64 str1=" ...