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[2][2];
void work() {int n;scanf("%d", &n);dp[0][0] = dp[0][1] = 1;dp[1][0] = dp[1][1] = cos(0.5);double ans = -1.0;for (int i = 2; i <= n - 1; ++i) {double res = sin(i * 0.5);if (res < 0) {if (i & 1) {ans = max(ans, 2 * res * dp[1][0] + sin(n - i));} else ans = max(ans, 2 * res * dp[0][0] + sin(n - i));} else {if (i & 1) {ans = max(ans, 2 * res * dp[1][1] + sin(n - i));} else ans = max(ans, 2 * res * dp[0][1] + sin(n - i));}res = cos(i);dp[0][0] = min(dp[0][0], res);dp[0][1] = max(dp[0][1], res);dp[1][0] = min(dp[1][0], res);dp[1][1] = max(dp[1][1], res);}printf("%0.9f\n", ans);
}int main() {
#ifdef localfreopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endifwork();return 0;
}

View Code

#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 + 20;
double dp[maxn][2];
void work() {int n;scanf("%d", &n);dp[0][0] = dp[0][1] = cos(0);dp[1][0] = dp[1][1] = 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 = 2; i <= n - 1; ++i) {double res = sin(i * 0.5);if (i & 1) {ans = max(ans, 2 * res * dp[i - 2][0] + sin(n - i));} else {ans = max(ans, 2 * res * dp[i - 2][1] + sin(n - i));}res = cos(i * 0.5);dp[i][0] = min(dp[i - 2][0], res);dp[i][1] = max(dp[i - 2][1], res);}printf("%0.9f\n", ans);
}int main() {
#ifdef localfreopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endifwork();return 0;
}

TLE code

转载于:https://www.cnblogs.com/liuweimingcprogram/p/7101833.html

1137 - Sin your life sin公式 + 枚举相关推荐

  1. sin cos tan cot公式

    在直角三角形中 sin@代表对边比斜边 cos@代表邻边比斜边 tan@代表对边比邻边 cot@代表邻边比对边 同角三角函数的基本关系式 倒数关系: 商的关系: 平方关系: tanα ·cotα=1 ...

  2. [再寄小读者之数学篇](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 ...

  3. php sin 函数,PHP sin()函数

    定义和用法 的SIN()函数返回给定角度的以弧度为单位的正弦的比率.在三角学中,角度的正弦定义为相对边和斜边的长度之比. sin(x)=对立/斜边 如果x = 90度,则sin(x)= 1,因为直角的 ...

  4. java math.sin()_Java Math sin() 使用方法及示例

    Java Math sin() 使用方法及示例 Java Math sin()返回指定角度的三角正弦值. sin()方法的语法为: Math.sin(double angle) sin()参数angl ...

  5. python怎么用sin函数_Python sin() 函数

    Python sin() 函数 描述 sin() 返回的x弧度的正弦值. 语法 以下是 sin() 方法的语法:import math math.sin(x) 注意:sin()是不能直接访问的,需要导 ...

  6. 如何用简单方法推导正弦函数的和角公式: sin(α+β)=sinαcosβ+cosαsinβ ?

    问题:看2014年湖北省高考理科数学题,选择题第6题: 这道题目答案是C,①③组是正交函数,②组不是正交函数.可以用数形结合方式,快速做出判断.详细解析如下 分析:要判断第一组函数是否是正交函数,要用 ...

  7. java math.sin()_Java Math sin()用法及代码示例

    java.lang.Math.sin()返回介于0.0和pi之间的角度的三角正弦.如果参数为NaN或无穷大,则结果为NaN.如果自变量为零,则结果为零,其符号与自变量相同.返回的值将在-1和1之间. ...

  8. java math.sin()_Java Math.sin() 方法

    Java Math.sin() 方法 java.lang.Math.sin() 是用来返回角度的正弦值.此方法返回-1至1之间的值. 1 语法 public static double sin(dou ...

  9. codeforces 233B(灵活运用公式枚举)

    B. Non-square Equation time limit per test 1 second memory limit per test 256 megabytes input standa ...

最新文章

  1. 如何创建复杂的机器学习项目?
  2. 警方:“外卖员因获差评杀人”为假消息 造谣者被刑拘
  3. COM线程模型的行为
  4. cmake交叉编译android,CMake Android 交叉编译
  5. Spring @Import 注解使用详解
  6. Codeforces Round #644 (Div. 3)(A-E)
  7. 计算机实现数论 奇偶排列问题
  8. spring mvc 工作流程
  9. 让版面充满空间感的海报PSD分层模板,你一定要看看!
  10. Caused by: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, mil_id)
  11. resin mysql_nginx+resin+mysql实现session共享
  12. 数据库系统基础教程复习
  13. 小米wifi驱动 linux,树莓派2B 安装小米wifi驱动
  14. 怎么用计算机打出音乐符号,音乐符号怎么打出来(所有)
  15. 如何搜索别人百度云网盘分享的资源
  16. HC-SR04模块初始化
  17. 汇编语言答案(王爽版)
  18. pkg-config的用法
  19. 【监控施工项目必备】
  20. 学习Direct3D的好地方

热门文章

  1. 伍六七带你学算法 入门篇-拼写单词
  2. php错误提示如何查询,php-如何显示我的MySQLi查询错误?
  3. README 规范和项目文档规范
  4. 2022-2028年中国氟硅橡胶产业发展动态及投资前景分析报告
  5. LeetCode简单题之“气球” 的最大数量
  6. XLearning - 深度学习调度平台
  7. Mask R-CNN用于目标检测和分割代码实现
  8. 人脸识别数据集精粹(下)
  9. mysql sql w3cschool_SQL复习(w3school)笔记
  10. java.lang.IllegalArgumentException: columnNames.length = 3, columnValues.length = 4