转载请注明出处,谢谢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. HTTP状态码(HTTP Status Code)【转】

    HTTP状态码(HTTP Status Code) 一些常见的状态码为: 200 - 服务器成功返回网页 404 - 请求的网页不存在 503 - 服务不可用 所有状态解释:点击查看 1xx(临时响应 ...

  2. Java并发编程实践(读书笔记) 任务执行(未完)

    任务的定义 大多数并发程序都是围绕任务进行管理的.任务就是抽象和离散的工作单元.   任务的执行策略 1.顺序的执行任务 这种策略的特点是一般只有按顺序处理到来的任务.一次只能处理一个任务,后来其它任 ...

  3. leetcode remove Nth Node from End python

    # Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = ...

  4. JDBC连接数据库概述

    直接介绍JDBC连接数据库的流程及其原理 创建一个以JDBC连接数据库的程序,包含7个步骤 1.加载JDBC数据库驱动 在连接数据库之前,首先要加载想要连接的数据库的驱动,就是数据库厂商提供的jar包 ...

  5. [LeetCode]题解(python):150-Evaluate Reverse Polish Notation

    题目来源: https://leetcode.com/problems/evaluate-reverse-polish-notation/ 题意分析: 给定一个数组,用这个数组来表示加减乘除,例如 [ ...

  6. python之字符串格式化(format)

    用法: 它通过{}和:来代替传统%方式 1.使用位置参数 要点:从以下例子可以看出位置参数不受顺序约束,且可以为{},只要format里有相对应的参数值即可,参数索引从0开,传入位置参数列表可用*列表 ...

  7. mini-httpd源码分析-version.h

    /* version.h - version defines for mini_httpd */ #ifndef _VERSION_H_ #define _VERSION_H_ #define SER ...

  8. 在VHDL中,“传输延迟”和“惯性延迟”

    传输延迟就是最容易理解的从输入变化到输出变化之间的延迟.对应语法是transport例如 b <= transport a after 20ns 惯性延迟考虑了电容效应,即如果输入是(相对)窄的 ...

  9. javascript学习笔记(1) 简单html语法

    <html> <head><meta http-equiv="content-type" content="text/html" ...

  10. SendMessage基本认识

    SendMessage基本认识 函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.而函数PostMessage不同,将一个消息寄送到一个线 ...