HDU 4498 Function Curve (分段, simpson)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove
最近太逗了。。。感觉成都要打铁了。。。只能给队友端茶送水了。。。。
积分都不会了。。。曲线长度不会求。。。。
写个代码,一堆SB错误。。。。。
纯属吐槽博文 。。。。。。
解法 :首先把n个函数以及y = 100求出交点。。。。把交点排序。
然后 处理每个区间,求出这段要积的函数
由于sqrt (1 + x ^ 2)不会求不定积分。。。只能simpson一下了。。。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 55;
const double eps = 1e-10;
int n;
double a[N] , b[N] , k[N];
vector <double> inter;
int dcmp (double d) {
return d < -eps ? -1 : d > eps;
}
double sqr (double d) {
return d * d;
}
void check (double d) {
if (dcmp (d) >= 0 && dcmp (d - 100) <= 0)
inter.push_back (d);
}
void get_inter () {
for (int i = 0 ; i < n ; i ++) {
if (dcmp (b[i] - 100) > 0) continue;
double x1 = sqrt ((100 - b[i]) / k[i]) + a[i];
double x2 = -sqrt ((100 - b[i]) / k[i]) + a[i];
check (x1) ; check (x2);
}
for (int i = 0 ; i < n ; i ++) {
for (int j = i + 1 ; j < n ; j ++) {
double A = (k[i] - k[j]);
double B = -(2 * k[i] * a[i] - 2 * k[j] * a[j]);
double C = k[i] * a[i] * a[i] + b[i] - k[j] * a[j] * a[j] - b[j];
if (dcmp (A) == 0) {
if (dcmp (B)) check (-C / B);
continue;
}
if (B * B - 4 * A * C < 0) continue;
if (dcmp (B * B - 4 * A * C) == 0) check (-B / 2 / A);
else {
double delta = sqrt (B * B - 4 * A * C);
double x1 = (-B + delta) / 2 / A , x2 = (-B - delta) / 2 / A;
check (x1); check (x2);
}
}
}
} double Function (double x , int i) {
return k[i] * sqr (x - a[i]) + b[i];
}
int best;
double function (double x) {
return sqrt (1 + sqr (2 * k[best] * (x - a[best])));
}
double simpson (double l , double r ) {
return (function (l ) + 4 * function ((l + r) / 2.0 ) + function (r )) * (r - l) / 6.0;
}
double simpson (double l , double r , double all , double eps) {
double m = (l + r) / 2.0;
double L = simpson (l , m) , R = simpson (m , r);
if (fabs (L + R - all) <= 15 * eps) return L + R + (L + R - all) / 15;
return simpson (l , m , L , eps / 2.0) + simpson (m , r , R , eps / 2.0);
}
double simpson (double l , double r , double eps) {
return simpson (l , r , simpson (l , r) , eps);
}
int main () {
#ifndef ONLINE_JUDGE
freopen ("input.txt" , "r" , stdin);
// freopen ("output.txt" , "w" , stdout);
#endif
int t ;
scanf ("%d" , &t);
while (t --) {
inter.clear ();
scanf ("%d" , &n);
for (int i = 0 ; i < n ; i ++) {
scanf ("%lf %lf %lf" , &k[i] , &a[i] , &b[i]);
}
get_inter ();
inter.push_back (0); inter.push_back (100);
sort (inter.begin () , inter.end ());
int size = inter.size() ;
double ans = 0;
for (int i = 1 ; i < size ; i ++) {
double x1 = inter[i - 1] , x2 = inter[i];
if (dcmp (x1 - x2) >= 0) continue;
double m = (x1 + x2) / 2.0;
best = 0;
for (int j = 1 ; j < n ; j ++) {
if (dcmp (Function (m , j) - Function (m , best)) < 0)
best = j;
}
if (dcmp (Function (m , best) - 100) >= 0) {
ans += (x2 - x1);
continue;
}
ans += simpson (x1 , x2 , 1e-8);
}
printf ("%.2f\n" , ans);
}
return 0;
}
HDU 4498 Function Curve (分段, simpson)的更多相关文章
- HDU 4498 Function Curve (自适应simpson)
Function Curve Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)To ...
- HDU 4498 Function Curve (分段,算曲线积分)
Function Curve Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)To ...
- HDU 5608 function [杜教筛]
HDU 5608 function 题意:数论函数满足\(N^2-3N+2=\sum_{d|N} f(d)\),求前缀和 裸题-连卷上\(1\)都告诉你了 预处理\(S(n)\)的话反演一下用枚举倍数 ...
- HDU 5608 - function
HDU 5608 - function 套路题 图片来自: https://blog.csdn.net/V5ZSQ/article/details/52116285 杜教筛思想,根号递归下去. 先搞出 ...
- HDU 6038 - Function | 2017 Multi-University Training Contest 1
/* HDU 6038 - Function [ 置换,构图 ] 题意: 给出两组排列 a[], b[] 问 满足 f(i) = b[f(a[i])] 的 f 的数目 分析: 假设 a[] = {2, ...
- 洛谷P1464 Function HDU P1579 Function Run Fun
洛谷P1464 Function HDU P1579 Function Run Fun 题目描述 对于一个递归函数w(a,b,c) 如果a≤0 or b≤0 or c≤0就返回值11. 如果a> ...
- HDU 5875 Function 【倍增】 (2016 ACM/ICPC Asia Regional Dalian Online)
Function Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】
Function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- HDU 5875 Function 优先队列+离线
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5875 Function Time Limit: 7000/3500 MS (Java/Others) ...
随机推荐
- JFinal开发web项目出现故障小记
导读 作为中国优秀的开源项目之中的一个JFinal有着极速开发的优点,是中小型应用开发的首选.在导师的建议下.我使用了JFinal来开发一个Java服务端应用,官方教程非常easy.就几十页(当然是中 ...
- Android平台音频信号FFT的实现
转载请标明出处:http://blog.csdn.net/sctu_vroy/article/details/45871823 功能:加载本地SD卡中moveDsp文件夹中的音频文件(包括录音获取文件 ...
- Java语言导学笔记 Chapter 9 IO
java.io 9.1.1 字符流 Reader为读取器(reader)提供API和部分实现,读取器是读取16位字符的流: Writer为写出器(writer)提供API和部分实现,写出器是写16位字 ...
- jquery ajax调用
client: <script type="text/javascript" language="javascript"> function jqu ...
- CentOS 配置防火墙操作实例(启、停、开、闭端口)CentOS Linux-FTP/对外开放端口(接口)TomCat相关
链接地址:http://blog.csdn.net/jemlee2002/article/details/7042991 CentOS 配置防火墙操作实例(启.停.开.闭端口): 注:防火墙的基本操作 ...
- MYSQL区分大小写
MYSQL区分大小写 1.linux下mysql安装完后是默认:区分表名的大小写,不区分列名的大小写: 2.用root帐号登录后,在/etc/my.cnf 中的[mysqld]后添加添加lower ...
- iOS对项目中第三方类库的管理——CocoaPods
http://blog.csdn.net/lengshengren/article/details/1767 唐巧的博客:http://www.devtang.com/blog/2014/05/25/ ...
- struts2中的表达元素标签使用详解
级联标签是使用:一级下拉框应该使用map对象的key集合作为下拉框元素,二级下了框应该使用一级下拉框对应的选择值自动的弹出待选择的元素值(集合) 页面代码如下:<s:set name=" ...
- Windows系统环境下一个Apache运行多个PHP版本
我个人机器上环境是基于Apache2.2运行的PHP5.2/4,如你想部署其他版本的PHP或在更多的版本之间切换,同理操作步骤是一致的. 依本人环境为例,机器上已经安装了PHP5.2版本, 所以首先重 ...
- php页面相互调用的知识点
目前我们有这样一个需求: (1) a.php 页面要使用 b.php 定义的函数,我们可以使用 如下指令 require require_once include include_once 举 ...