转载请注明出处,谢谢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)的更多相关文章

  1. HDU 4498 Function Curve (自适应simpson)

    Function Curve Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)To ...

  2. HDU 4498 Function Curve (分段,算曲线积分)

    Function Curve Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)To ...

  3. HDU 5608 function [杜教筛]

    HDU 5608 function 题意:数论函数满足\(N^2-3N+2=\sum_{d|N} f(d)\),求前缀和 裸题-连卷上\(1\)都告诉你了 预处理\(S(n)\)的话反演一下用枚举倍数 ...

  4. HDU 5608 - function

    HDU 5608 - function 套路题 图片来自: https://blog.csdn.net/V5ZSQ/article/details/52116285 杜教筛思想,根号递归下去. 先搞出 ...

  5. HDU 6038 - Function | 2017 Multi-University Training Contest 1

    /* HDU 6038 - Function [ 置换,构图 ] 题意: 给出两组排列 a[], b[] 问 满足 f(i) = b[f(a[i])] 的 f 的数目 分析: 假设 a[] = {2, ...

  6. 洛谷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> ...

  7. 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 ...

  8. 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 ...

  9. HDU 5875 Function 优先队列+离线

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5875 Function Time Limit: 7000/3500 MS (Java/Others) ...

随机推荐

  1. ACM/ICPC2014鞍山现场赛E hdu5074Hatsune Miku

    题目链接:pid=5074">http://acm.hdu.edu.cn/showproblem.php?pid=5074 题意: 给定一个m*m的矩阵mp.然后给定一个长度为n的序列 ...

  2. asp.net中自定义验证控件

    在windows2003中,可能iis版本太底,不支持TextBox的类型设为Number类型,所以会报错,所以去掉后直接用验证控件来控制必须输入数字好了. <asp:RegularExpres ...

  3. android监听键盘

    android中的带有输入功能的页面布局经常被弹出的键盘遮挡,一种处理方法是监听键盘的弹出,设置布局的padding或隐藏某些占位控件,使得输入框不被键盘遮挡.一种常用的方法是当Activity设置为 ...

  4. C++学习笔录2

    1.如果一个类要成为基类,那么它的成员变量声明成受保护的变量,既用关键字protected修饰. 2.处理共同继承产生的二义性:采用虚继承方式,当出现两个相同的成员时,编译器会自动删除其中一个.其方法 ...

  5. 不可以为null值的自定义类型

    1.今天早上编码发现,这很奇怪 再一看,原来是DateTime类型,DateTime进去一看发现时Struct类型,原来如此

  6. Module 模式 以及 揭示模式。

    ---恢复内容开始--- Module模式 : 在传统软件工程中为类提供私有和公有封装的方法. 在js中: Module 模式 使用闭包封装 私有状态和组织. 该模式,返回一个公有的API,而其他的一 ...

  7. this指针与function变量--this究竟指向哪里?

    参考文章:<深入浅出 JavaScript 中的 this> http://www.ibm.com/developerworks/cn/web/1207_wangqf_jsthis/ Ja ...

  8. 比callback更简洁的链式执行promise

    promise自己理解的也不够深刻,具体知识点不在这里细说了 直接上个例子,清晰明了,自己去悟吧 <script type="text/javascript"> //模 ...

  9. windows如何安装和配置mongodb

    https://docs.mongodb.com/v3.0/tutorial/install-mongodb-on-windows/

  10. 【java】for循环输出数字金字塔

    输出下列数字金字塔.    1  121 123211234321 public class deng { public static void main(String args[]) { int n ...