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 ...
随机推荐
- 《linux内核设计与实现》读书笔记第十七章
第17章 设备与模块 四种内核成分 设备类型:在所有 Unix 系统中为了统一普通设备的操作所采用的分类. 模块: Linux 内核中用于按需加载和卸载目标码的机制. 内核对象:内核数据结构中支持面向 ...
- 学习笔记---C/C++语法
一.char *s char s[] 区别 char *s中的s是指针,而指针是指向一块内存区域,它指向的内存区域的大小可以随时改变,而且当指针指向常量字符串时,它的内容是不可以被修改的,否则在运行时 ...
- java常见的开发工具
http://www.csdn.net/article/1970-01-01/2824723 http://zhidao.baidu.com/link?url=D8FdJxeFd-z-LV1OfZuZ ...
- Base64加密算法封装
/// <summary>/// 实现Base64加密解密/// </summary>public sealed class Base64{/// <summary> ...
- iOS开发路线简述
1 iOS开发环境1.1 开发环境标准的配置是MacOSX+Xcode.MacOSX的话首选用苹果电脑,Macmini最便宜只要4000多就好了然后自己配一个显示器,MacBookPro 也可以,不推 ...
- eclipse下SVN同步时忽略target文件夹
直接干货:window-->preferences-->team-->Ignored Resource-->Add Pattern-->新建一个*/target/*--& ...
- 使用Charles检测HTTPS网站的数据包
1.下载Charles 下载地址:https://www.charlesproxy.com/download/ 2.安装Charles的证书 选择Help->SSL Proxying->I ...
- lua协程一则报错解决“attempt to yield across metamethod/C-call boundary”
问题 attempt to yield across metamethod/C-call boundary 需求跟如下帖子中描述一致: http://bbs.chinaunix.net/forum.p ...
- rhel 7.0, windows10双系统grub2设置
因为在win10基础上装了rhel7,但是启动时却没有win10的启动项,下面的方法解决此问题. $ su #root登录 $ cd /boot/grub2 1. 简单执行grub2-mkconfig ...
- PostgreSQL 锁监控
PG>9.2 postgres=# SELECT blocked_locks.pid AS blocked_pid,postgres-# blocked_activity.usename AS ...