hdu 4401 Battery
这里只给出代码,感兴趣的可以作以参考:
#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的更多相关文章
- [GodLove]Wine93 Tarining Round #6
比赛链接: http://vjudge.net/contest/view.action?cid=47642#overview 题目来源: 2012 ACM/ICPC Asia Regional Jin ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
随机推荐
- shell 条件判断
一.数值判断 INT1 -eq INT2 INT1和INT2两数相等为真 INT1 -ne INT2 INT1和INT2两数不等为真 INT1 -gt INT2 ...
- GDB调试32位汇编堆栈分析
GDB调试32位汇编堆栈分析 测试源代码 #include <stdio.h> int g(int x){ return x+5; } int f(int x){ return g(x)+ ...
- web app 自适应方案总结 关键字 弹性布局之rem
关于rem,主要参考文档 1.腾讯ISUX (http://isux.tencent.com/web-app-rem.html) 2.http://www.w3cplus.com/css3/defin ...
- Python之路【第十八章】:Web框架
Web框架本质 1.众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端 #!/usr/bin/env python # -*- codin ...
- python---基础之模块,列表,元组,字典
1. 模块 写模块的时候尽量不要和系统自带的模块的名字相同 调用模块的时候,会先在当前目录下查找是否有这个模块,然后再会如python的环境变量中查找 a.模块1:sys 代码如下: import ...
- Windows7+VirtualBox+Ubuntu本地开发环境搭建
首先下载相应的VirtualBox和Ubuntu镜像文件 安装Ubuntu操作系统 一 网络设置 将虚拟机的network连接模式设置为Bridge模式,注意无线网卡要与本机的无线网卡名称一致 在wi ...
- .net 调用java rest ful api 实例
注意post的参数组合 HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = &quo ...
- 基于Java Mina框架的部标808服务器设计和开发
在开发部标GPS平台中,部标808GPS服务器是系统的核心关键,决定了部标平台的稳定性和行那个.Linux服务器是首选,为了跨平台,开发语言选择Java自不待言. 我们为客户开发的部标服务器基于Min ...
- 解读ContentResolver和ContentProvider
转自:http://cthhqu.blog.51cto.com/7598297/1281217 1. ContentProvider的概述 ContentProvider: (Official Def ...
- 屌丝程序员的梦想 (六) 我也写个开源CMS
离开上家公司之后,我没急着找下家公司,一直以来都是为公司做各个细小的功能却没有属于自己的完整的项目 思来想去,我准备用自己熟悉的thinkphp 和 extjs写一个开源的cms,从用户系统,文章系统 ...