Gym - 101257G 24【二分+看题】
2017-02-25 18:36
316 查看
题目链接:https://vjudge.net/problem/Gym-101257G
题意:有一道分值为sa的题,n个人一起写这道题,给出每个人的当前分数,和每个人写不出(一定要注意,比赛就是因为漏看了这里,WA好多次)这道题的概率,,让你输出有反超现象出现的期望
解析:每个人的当前分数是按降序排列的,所以排最后的开始往前看,数值在(a[n-1]-1到a[n-2]+sa)这个区间的都是会有反超情况发生的,所以可以先前缀和处理概率,然后再用二分查找来获取需要乘的区间位置就好
题意:有一道分值为sa的题,n个人一起写这道题,给出每个人的当前分数,和每个人写不出(一定要注意,比赛就是因为漏看了这里,WA好多次)这道题的概率,,让你输出有反超现象出现的期望
解析:每个人的当前分数是按降序排列的,所以排最后的开始往前看,数值在(a[n-1]-1到a[n-2]+sa)这个区间的都是会有反超情况发生的,所以可以先前缀和处理概率,然后再用二分查找来获取需要乘的区间位置就好
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <queue> using namespace std; const int maxn = 2*1e5+100; int a[maxn]; double p[maxn]; double sum[maxn]; bool cmp(const int &A,const int &B) { return A>B; } int main(void) { int n,sa; memset(sum,0,sizeof(sum)); scanf("%d %d",&n,&sa); for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++) scanf("%lf",&p[i]); sum[1] = p[0]; for(int i=1;i<n;i++) sum[i+1] = sum[i]+p[i]; double ans = 0; for(int i=0;i<n;i++) { int l=upper_bound(a,a+i+1,a[i]+sa,cmp)-a; int r=lower_bound(a,a+i+1,a[i],cmp)-a; ans+=(sum[r]-sum[l])*(1.0-p[i]); } printf("%.9f\n",ans); return 0; }
相关文章推荐
- Gym - 101257G 24-二分和upper_bound的应用
- Gym - 101257G 24
- GYM 101149 B.No Time for Dragons【二分+贪心】
- Gym - 101190E Expect to Wait(数形结合 , 二分, 查分)
- Gym - 101194D(二分
- 【二分】【半平面交】Gym - 101309J - Jungle Outpost
- [二分答案 2-SAT验证 前缀后缀优化建图 线段树优化建图] Codeforces gym 100159 Facebook Hacker Cup 2012 I. Unfriending
- Codeforces Gym 100741G Yet Another Median Task 二分乱搞
- Gym - 100570E:Palindrome Query (hash+BIT+二分维护回文串长度)
- Gym - 101194D(二分
- GYM 101243 J. Architect of Your Own Fortune【二分匹配】
- GYM 100801 J.Journey to the “The World’s Start”(二分+dp+线段树)
- Codeforces Gym 100425A Luggage Distribution 二分 数学
- Gym 100425A Luggage Distribution (组合数学,二分)
- Gym - 101194D(二分
- Gym - 100283F F. Bakkar In The Army —— 二分
- Codeforces Gym 101505D Orchard Division(离散化+树状数组+扫描线+二分)
- loj #6002. 「网络流 24 题」最小路径覆盖(二分匹配)
- Gym 100883J palprime(二分判断点在凸包里)
- 【二分】【动态规划】Gym - 101156E - Longest Increasing Subsequences