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 ...
随机推荐
- 数值分析之奇异值分解(SVD)篇
在很多线性代数问题中,如果我们首先思考若做SVD,情况将会怎样,那么问题可能会得到更好的理解[1]. --Lloyd N. ...
- asp.net mvc 表单相关
1. <form action="/controller/action" method="post"> ... </form> *act ...
- magento事件(event)的dispatchEvent(分发)和catchEvent(获取)
当你需要扩展Magento的核心的功能时有两个选择: (1)重写(override)Magento的core classes (2)使用Magento的event-driven 机制 由于你只能重写一 ...
- [翻译]类型双关不好玩:C中使用指针重新解释是坏的
原文地址 Type punning isn't funny: Using pointers to recast in C is bad. C语言中一个重新解释(reinterpret)数据类型的技巧有 ...
- Mac mySql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)的解决办法
我的环境:Mac 10.11.6 ,mysql 5.7.14 . mac mySql 报错ERROR 2002 (HY000): Can't connect to local MySQL serv ...
- 发布Live Writer代码着色插件CNBlogs.CodeHighlighter
在解决了使用Windows Live Writer发博所遇到的"建分类.加标签.写摘要"与"设置EntryName"的四个问题之后,我们趁热打铁,解决了第五个问 ...
- CSS样式常用属性整理
web工程师是最近5年刚刚兴起的一门高薪职业,人们的专注度越来越高. 那么前端除了学习html标签之外还需要掌握什么知识点呢? 为大家整理了一个和HTML标签密不可分的知识要点--<CSS样式常 ...
- [SharePoint 2010] 自定义字段类型开发(二)
在SharePoint 2010中实现View Action Button效果. http://www.sharepointblogs.be/blogs/vandest/archive/2008/06 ...
- kafka集群搭建和使用Java写kafka生产者消费者
1 kafka集群搭建 1.zookeeper集群 搭建在110, 111,112 2.kafka使用3个节点110, 111,112 修改配置文件config/server.properties ...
- SpringMVC问题- MultipartConfig 配置问题以及解决方式
http://www.cnblogs.com/weilu2/p/springmvc_fileupload_with_servlet_3_0.html