Codeforces 832 C Strange Radiation
来源:互联网 发布:知乎怎么用 编辑:程序博客网 时间:2024/05/21 04:26
题目地址
题意:就是告诉你每个人的位置,速度,以及行进方向,让你求出把一个炸弹放在某个位置上的全部人出去的最短时间,炸弹爆炸产生的冲击波会给相同方向的人应该s的速度使得它的速度为v+s
思路:二分时间,通过时间来求向右和向左的区间,如果区间有交集,就是可以放炸弹,反之则不行。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <iomanip>//cout << fixed << setprecision(10) << ans << endl;小数#include <algorithm>#define N 100010#define M 510#define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1using namespace std;const LL mod = 1e9 + 7;const double eps = 1e-9;int n, s;struct node { LL x, v, d;}num[N];bool check(double times) { LL l1 = 1000001, r1 = 0, l2 = 1000001, r2 = 0; for (int i = 0; i < n; i++) { if (num[i].d == 1) { if (num[i].v*times >= num[i].x) { l1 = 0; r1 = 1000000; } else if ((num[i].v + s)*times >= num[i].x) { l1 = min(l1, num[i].x); r1 = max(r1, num[i].x + (LL)((s*times + num[i].v*times - num[i].x)*(s - num[i].v)) / s); } } else { if (num[i].v*times >= 1000000 - num[i].x) { l2 = 0; r2 = 1000000; } else if ((num[i].v + s)*times >= 1000000 - num[i].x) { r2 = max(r2, num[i].x); l2 = min(l2, num[i].x - (LL)((s*times + num[i].v*times - 1000000 + num[i].x)*(s - num[i].v)) / s); } } } if (l1 > r2 || l2 > r1) { return 0; } return 1;}int main() { cin.sync_with_stdio(false); while (cin >> n >> s) { for (int i = 0; i < n; i++) { cin >> num[i].x >> num[i].v >> num[i].d; } double l = 0, r = 1000000; double mid; double ans; for (int i = 0; i < 100;i++) { mid = (l + r) / 2; if (check(mid)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << fixed << setprecision(10) << ans << endl; } return 0;}
PS:贴一个错误的二分代码,虽然我不知道为什么是错的,我看了别人的代码那样写才AC了,希望有大佬告诉一下我
double l = 0, r = 1000000;double mid;double ans;while (l < r) { mid = (l + r) / 2; if (check(mid)) { ans = mid; r = mid - 1; } else { l = mid + 1; }}
阅读全文
0 0
- Codeforces 832 C Strange Radiation
- CodeForces 832 C. Strange Radiation
- Codeforces Round #425 (Div. 2) C-Strange Radiation(二分答案)
- Codeforces 484C Strange Sorting(置换)
- codeforces 719C. Efim and Strange Grade
- [Codeforces #373 (Div. 2) C. Efim and Strange Grade] 模拟
- codeforces 719C Efim and Strange Grade (复杂模拟)
- codeforces 719 C. Efim and Strange Grade(模拟)
- Codeforces Round #373 (Div. 2) C: Efim and Strange Grade
- [codeforces] C - Efim and Strange Grade 模拟+贪心
- codeforces 719 C Efim and Strange Grade (模拟)
- Codeforces 719C Efim and Strange Grade 贪心+模拟
- Codeforces 719C Efim and Strange Grade【贪心】
- Educational Codeforces Round 30 C. Strange Game On Matrix
- Codeforces 873C Strange Game On Matrix【贪心】水题
- codeforces 873 C. Strange Game On Matrix【贪心】
- codeforces-305A Strange Addition
- Codeforces Round #373 (Div. 2) -- C - Efim and Strange Grade (贪心)
- 【简记】Java Web 内幕——编码问题
- javaWEB开发中的 / 傻傻分不清楚
- FMEA:失效模式与影响分析
- Mongodb从0到1系列六: 复制集
- ZooKeeper 学习 (一) ZooKeeper的基本概念
- Codeforces 832 C Strange Radiation
- 古文觀止卷七_原道_韓愈
- 注意程序的[error]log
- 各类MQ比较
- springframework Request method 'GET' not supported
- hibernate与spring整合:配置事务之后并不会滚的问题
- ubutu搭建pptp
- KMP字符串模式匹配算法实现
- 【面试题】判断一棵二叉树是否是完全二叉树