这里只给出代码,感兴趣的可以作以参考:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <functional>
#include <cmath>
#include <iostream>
#include <assert.h>
#pragma comment(linker, "/STACK:102400000,102400000")
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define mp std :: make_pair
#define st first
#define nd second
#define keyn (root->ch[1]->ch[0])
#define lson (u << 1)
#define rson (u << 1 | 1)
#define pii std :: pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define type(x) __typeof(x.begin())
#define foreach(i, j) for(type(j)i = j.begin(); i != j.end(); i++)
#define FOR(i, s, t) for(int i = (s); i <= (t); i++)
#define ROF(i, t, s) for(int i = (t); i >= (s); i--)
#define dbg(x) std::cout << x << std::endl
#define dbg2(x, y) std::cout << x << " " << y << std::endl
#define clr(x, i) memset(x, (i), sizeof(x))
#define maximize(x, y) x = max((x), (y))
#define minimize(x, y) x = min((x), (y))
using namespace std;
typedef long long ll;
const int int_inf = 0x3f3f3f3f;
const ll ll_inf = 0x3f3f3f3f3f3f3f3f;
const int INT_INF = (int)((1ll << ) - );
const double double_inf = 1e30;
const double eps = 1e-;
const double pi = acos(-.);
typedef unsigned long long ul;
typedef unsigned int ui;
inline int readint() {
int x;
scanf("%d", &x);
return x;
}
inline int readstr(char *s) {
scanf("%s", s);
return strlen(s);
} class cmpt {
public:
bool operator () (const int &x, const int &y) const {
return x > y;
}
}; int Rand(int x, int o) {
//if o set, return [1, x], else return [0, x - 1]
if (!x) return ;
int tem = (int)((double)rand() / RAND_MAX * x) % x;
return o ? tem + : tem;
}
ll ll_rand(ll x, int o) {
if (!x) return ;
ll tem = (ll)((double)rand() / RAND_MAX * x) % x;
return o ? tem + : tem;
} void data_gen() {
srand(time());
freopen("in.txt", "w", stdout);
int kases = ;
//printf("%d\n", kases);
while (kases--) {
int L = Rand(, ) + ;
int n = Rand(L - , ) + ;
int buf[], p = ;
FOR(i, , n) buf[i] = Rand(L, );
buf[++n] = , buf[++n] = L;
sort(buf + , buf + n + );
n = unique(buf + , buf + n + ) - buf - ;
printf("%d %d\n", L, n);
int t1 = Rand(, ) + ;
int t2 = Rand(, ) + ;
while (t2 == t1) {
t2 = Rand(, ) + ;
}
if (t1 > t2) swap(t1, t2);
printf("%d %d\n", t1, t2);
FOR(i, , n) {
printf("%d %d\n", buf[i], Rand(, ));
}
puts("\n");
}
puts("0 0");
} const int maxn = 1e3 + ;
pii a[maxn];
int n, L;
int t1, t2;
struct Line {
int lhs, rhs;
double theta;
int o;
Line() {}
Line(int _lhs, int _rhs, double _ta, int _o) {
lhs = _lhs, rhs = _rhs, theta = _ta, o = _o;
}
bool operator < (const Line &other) {
return theta > other.theta || theta == other.theta && rhs > other.rhs ||
theta == other.theta && rhs == other.rhs && lhs > other.lhs;
}
}lines[maxn * maxn];
int k;
double shadow, H;
bool inq[maxn]; double cal(double theta1, double theta2) {
if (abs(theta1 - theta2) < eps) return ;
double X = abs(theta1 - pi / ) < eps ? : H / tan(theta1);
double ret = (cos(theta2) - cos(theta1)) * (L - shadow + X) - H * (sin(theta1) - sin(theta2));
shadow += abs(theta2) < eps ? L - shadow : H / tan(theta2) - X;
return ret;
} double solve(int l, int r) {
shadow = H = ;
k = ;
FOR(i, , n) {
inq[i] = ;
H += a[i].nd;
double mini = (double)ll_inf;
int mk = ;
ROF(j, i - , ) {
double ang_tan = (double)a[i].second / (a[i].first - a[j].first);
lines[k++] = Line(j, i, atan(ang_tan), );
if (a[i].second <= a[j].second) break;
ang_tan = (double)(a[i].second - a[j].second) / (a[i].first - a[j].first);
lines[k++] = Line(j, i, atan(ang_tan), );
}
}
double ang_l = pi / * ( - l), ang_r = pi / * ( - r);
lines[k++] = Line(, , ang_l, ), lines[k++] = Line(, , ang_r, );
sort(lines, lines + k);
double ans = ;
bool okay = false;
double pre = pi / ;
FOR(i, , k - ) {
int o = lines[i].o;
int lhs = lines[i].lhs, rhs = lines[i].rhs;
double ang = lines[i].theta;
double res = cal(pre, ang);
if (okay) ans += res;
if (o == ) break;
else if (o == ) okay = true;
else if (o == && inq[rhs]) inq[rhs] = , H -= a[rhs].nd, mk = ;
else if (o == && inq[lhs]) H += a[rhs].nd - a[lhs].nd, inq[lhs] = , inq[rhs] = , mk = ;
pre = ang;
}
return abs(ans * / pi);
} int main() {
//data_gen(); return 0;
//C(); return 0;
int debug = ;
if (debug) freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int kases = ;
while (~scanf("%d%d", &L, &n) && n) {
++kases;
t1 = readint(), t2 = readint();
FOR(i, , n) scanf("%d%d", &a[i].st, &a[i].nd);
double ans = ;
if (t1 >= ) ans += solve(t1, t2);
else {
if (t2 > ) ans += solve(, t2), t2 = ;
FOR(i, , n) a[i].first = L - a[i].st;
FOR(i, , n / ) swap(a[i], a[n + - i]);
ans += solve( - t2, - t1);
}
printf("%.5f\n", ans);
}
return ;
}

hdu 4401 Battery的更多相关文章

  1. [GodLove]Wine93 Tarining Round #6

    比赛链接: http://vjudge.net/contest/view.action?cid=47642#overview 题目来源: 2012 ACM/ICPC Asia Regional Jin ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. How to inspect who is caller of func and who is the class of instance

    1. Who is the class of self instance ? class aa(object): def a(self): if self.__class__.__name__ == ...

  2. [flex布局]-flex教程

    简介:2009年,W3C提出了一种新的方案----Flex布局,可以简便.完整.响应式地实现各种页面布局.目前,它已经得到了所有浏览器的支持,这意味着,现在就能很安全地使用这项功能. Flex布局是什 ...

  3. 数据库连接池:Druid

    转自: http://www.cnblogs.com/windlaughing/p/3287501.html Java连接数据库方法概述 java.sql提供了一些接口和类,用于支持数据库增删改查等相 ...

  4. 用Pyinstaller打包发布exe应用

    有时候编写的Python程序依赖很多,如果要在不同服务器上安装python环境等东西有点得不偿失了.这时候可以使用pyinstaller和py2exe,能够将python程序打包成可执行的exe文件, ...

  5. 指定的架构无效。错误: CLR 类型到 EDM 类型的映射不明确

    在使用WebService开发时,同时使用了EF和linq,查询数据时,使用linq(查询订单)可以正常拉出数据, 但是使用EF(查询用户)却会报以下错误: {"指定的架构无效.错误: \r ...

  6. 本机,同机房,同城,异地,不同城,腾讯云ping延时值

    本机,同机房,同城,异地,不同城,腾讯云ping延时值 ping本机: 0.01ms ping同机房机器: 0.1ms ping同城机器: 1ms ping不同城机器: 20ms 北(南)方ping南 ...

  7. RabbitMQ学习总结 第七篇:RCP(远程过程调用协议)

    在http://www.cnblogs.com/leocook/p/mq_rabbitmq_2.html 这篇博文中我们实现了怎么去使用work queue来把比较耗时的任务分散给多个worker. ...

  8. Python之路-python(html、css)

    html: 概述: HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样 ...

  9. [Android Tips] 24. Gradle listing project dependencies

    ./gradlew app:dependencies or install this Android Studio Plugin https://github.com/rholder/gradle-v ...

  10. GPS部标平台的架构设计(九)-GPS监控客户端设计

    交通部的部标过检,所有的测试都是从客户端发起的,也是在客户端体现的,在客户端承载了部标标准所要求的所有的功能,是整个部标平台当中工作量最大的部分,也是最繁琐的部分. 客户端设计面临两个问题: 1.基于 ...