Gym - 101257G 24-二分和upper_bound的应用
2017-03-22 17:46
260 查看
输入有人数 和一道题的分数
在输入每个人的当前分数和 他做不对这道题的概率
问有实现反超的概率(每个人的反超概率相加)
因为考虑到加法原理,所以这种概率是可以累加的,
还有一种情况就是,如果分数是10分,一个人15,一个人2分,那么即使那个人作对了题 12<15仍然无法实现反超。
思路,二分,求出 a[i]—a[i]+sa(题目分数)这其中的概率相加(都是做不对的概率哦),然后再乘以 本a[i]哥能作对这道题的概率。
在输入每个人的当前分数和 他做不对这道题的概率
问有实现反超的概率(每个人的反超概率相加)
因为考虑到加法原理,所以这种概率是可以累加的,
还有一种情况就是,如果分数是10分,一个人15,一个人2分,那么即使那个人作对了题 12<15仍然无法实现反超。
思路,二分,求出 a[i]—a[i]+sa(题目分数)这其中的概率相加(都是做不对的概率哦),然后再乘以 本a[i]哥能作对这道题的概率。
#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; //由对upper的理解可以知道,这里返回的是第一个小于等于a[i]de; //因为是降序,所以一定是a[i]; //但是如果好几个数都一样就错了。 //int r=i; ans+=(sum[r]-sum[l])*(1.0-p[i]); } printf("%.9f\n",ans); return 0; }
相关文章推荐
- Gym - 101257G 24【二分+看题】
- Codeforces 600B Queries about less or equal elements(二分、upper_bound()的应用)
- 二分搜索:lower_bound, upper_bound
- 二分lower_bound()与upper_bound()的运用
- 二分查找:binary_search、lower_bound和upper_bound的实现
- Leetcode 34 Search for a Range (二分搜索 lower_bound和upper_bound)
- STL里边二分的lower_bound函数与upper_bound函数的最常见的用法
- STL中的二分查找——lower_bound 、upper_bound 、binary_search
- c++ 二分查找的函数 lower_bound & upper_bound & binary_search
- STL 中 lower_bound 与 upper_bound 与 二分查找
- (转)STL之二分查找(binary_search(),lower_bound(),upper_bound() )
- STL中的二分查找——lower_bound 、upper_bound 、binary_search
- 二分lower_bound()与upper_bound()的运用
- codeforces #479D# Long Jumps(二分upper_bound)
- STL中二分查找相关算法(binary_search, lower_bound, upper_bound, equal_range)
- STL中的二分查找——lower_bound 、upper_bound 、binary_search
- LeetCode:Search Insert Position,Search for a Range (二分查找,lower_bound,upper_bound)
- STL 二分查找三兄弟(lower_bound(),upper_bound(),binary_search())
- STL中的二分查找———lower_bound,upper_bound,binary_search
- 二分查找与STL中的lower_bound(),upper_bound(),binary_search()