转载请注明出处,谢谢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. Entityframework 伪CodeFirst开发模式应用于Sqlite数据库

    因为最近没有时间深入的研究EntityFramework的内部机制,所以具体的实现并不十分了解.微软最初的初衷是开发出一套通用的数据库访问逻辑,实现对Dal数据访问层的高度封装,其中就用到了工厂模式和 ...

  2. notepad++中的zencoding的快捷键修改[转]

    在notepad++自己的”设置-->管理快捷键“中,找不到zen coding的快捷键,我又不想改掉已经用习惯了的ctrl+/,结果就用了一种比较偏门的修改快捷键的解决方案,希望可以帮到有同样 ...

  3. Linux PostgreSQL 基础配置指南

    1安装PostgreSQL:      yum install postgresql-server    2创建数据库          createdb mydb          如果出现以下错误 ...

  4. 浅谈C中的指针和数组(七)

    现在到揭露数组名本质的时候了,先给出三个结论: (1)数组名的内涵在于其指代实体是一种数据结构,这种数据结构就是数组: (2)数组名的外延在于其可以转换为指向其指代实体的指针,而且是一个指针常量: ( ...

  5. leetcode Invert Binary Tree python

    # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...

  6. Ajax中XML和JSON格式的优劣比较

    刚做完一个小的使用Ajax的项目.整个小项目使用JavaScript做客户端,使用PHP做服务器端.利用xmlHttpRequest组件作为交互工具,利用XML作为数据传输的格式.做完后基本做一个简单 ...

  7. 你的阅读造就了你 You are what you read

    在豆瓣上看到的一篇很有思想和正能量的文章,在这里请允许我用原创的方式来呈现给大家.如果你是在校的大学生或者研究生博士生,这篇文章会让你有很多的共鸣.如果你已真正的踏入这个社会,也将受益匪浅.   电脑 ...

  8. hdu 5649 DZY Loves Sorting 二分+线段树

    题目链接 给一个序列, 两种操作, 一种是将[l, r]里所有数升序排列, 一种是降序排列. 所有操作完了之后, 问你a[k]等于多少. 真心是涨见识了这题..好厉害. 因为最后只询问一个位置, 所以 ...

  9. C#.NET中的CTS、CLS和CLR

    以下内容来自:http://www.cnblogs.com/zagelover/articles/2741370.html 在学习.NET的过程中,都会不可避免地接触到这三个概念,那么这三个东西是什么 ...

  10. CSS自学笔记(1):CSS简介

    一.什么是CSS CSS(Cascading Style Sheet(级联样式表))是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言. ...