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

#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. JAVA基础篇NO1--环境变量的配置及命名规则

    标签(空格分隔): java基础 一:计算机概述 计算机:硬件和软件 硬件:控制器 运算器 存储器 输入和输出设备       存储器:外存(硬盘) 内存 软件:系统软件 应用软件   系统软件:wi ...

  2. 非常适用的Sourceinsight插件,提高效率事半功倍

    一直使用sourceinsight编辑C/C++代码,sourceinsight是一个非常好用的编辑工具可以任意定位,跳转,回退,本人一直 使用该工具做C/C++开发,sourceinsight能够满 ...

  3. php usort 按照数组中的某个键值排序

    //php usort 按照数组中的某个键值排序 如果第一个参数小于第二个参数 -> 返回小于0的整数如果第一个参数等于于第二个参数 -> 返回等于0的整数如果第一个参数大于于第二个参数 ...

  4. windows平台 查看 dll 程序集 PublicKeyToken

    打开Developer Command Prompt for VS20** 命令工具 路径:点击开始->所有程序->Microsoft Visual Studio 20** ->Vi ...

  5. @Html.Raw()

    在用VS 2015写代码时,匹配邮箱的正则表达式 /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/​ @报错  主要因为 @是MVC里的关键字,所以不能直 ...

  6. 使用intellij的svn时提示出错: Can't use Subversion command line client: svn.Errors found while svn working copies detection.

    使用Intellij的svn时提示出错:Can't use Subversion command line client: svn. Errors found while svn working co ...

  7. Java内部DNS查询实现和参数设置

    一.Java内部DNS查询 Java使用域名查询时,用的自己内部的域名实现机制,最后都是交给InetAddress去做DNS解析. 源码分析参考:http://blog.arganzheng.me/p ...

  8. IIS无法加载字体文件(*.woff,*.svg)的解决办法

    在编写前端代码的过程中经常会遇到使用特定的字体(*.woff,*.svg),此时在加载字体时请求会被返回 Failed to load resource: the server responded w ...

  9. Python基础学习-Python中最常见括号()、[]、{}的区别

    Python中最常见括号的区别: 在Python语言中最常见的括号有三种,分别是:小括号().中括号[].花括号{}:其作用也不相同,分别用来代表不同的Python基本内置数据类型. Python中的 ...

  10. opencv 抠图联通块(c接口)

    #include "stdio.h" #include "iostream" #include "opencv/cv.h" #include ...