题意: 不概括了..太长了..

额第一次做这种问题 算是概率dp吗?

保存前缀项中第一个和最后一个的概率 然后每添加新的一项 就解除前缀和第一项和最后一项的关系 并添加新的一项和保存的两项的关系

这里关系指的是两者相邻会产生的额外收入(其中一个满足条件就能得到 因此公式是 2000 * (rate[a] * rate[b] + rate[a] * ( 1 - rate[b]) + rate[b] * (1 - rate[a]))

至于一开始为什么老是调不过去呢..我发现添加第三项的时候前两项是不用解除关系的...

啊啊啊啊这题我敲了大半个小时敲得都烦死了= = 不过交上去直接Pretest Pass了

代码稍显冗长.. 凑和着看吧..

#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define INF 0x3f3f3f3f
#define mem(str,x) memset(str,(x),sizeof(str))
#define STOP puts("Pause");
using namespace std;
typedef long long LL; int main()
{
int n, p;
int l, r;
double rate[], ans = ;
scanf("%d%d", &n, &p);
scanf("%d%d", &l, &r);
if(l % p) rate[] = (double)(r / p - l / p) / (r - l + );
else rate[] = (double)(r / p - l / p + ) / (r - l + );
//printf("i = %d rate = %f\n", 1, rate[0]);
for(int i = ; i <= n; i++){
scanf("%d%d", &l, &r);
if(l % p) rate[] = (double)(r / p - l / p) / (r - l + );
else rate[] = (double)(r / p - l / p + ) / (r - l + );
if(i == ){
ans += (rate[] * rate[] + rate[] * ( - rate[]) + rate[] * ( - rate[])) * ;
rate[] = rate[];
}
else if (i == ){
ans += (rate[] * rate[] + rate[] * ( - rate[]) + rate[] * ( - rate[])) *
+ (rate[] * rate[] + rate[] * ( - rate[]) + rate[] * ( - rate[])) * ;
rate[] = rate[];
}
else{
ans += (rate[] * rate[] + rate[] * ( - rate[]) + rate[] * ( - rate[])) *
+ (rate[] * rate[] + rate[] * ( - rate[]) + rate[] * ( - rate[])) *
- (rate[] * rate[] + rate[] * ( - rate[]) + rate[] * ( - rate[])) * ;
rate[] = rate[];
}
//printf("i = %d rate = %f ans = %f\n", i, rate[2], ans);
}
printf("%f\n", ans);
return ;
}

Codeforces Round #341 Div.2 C. Wet Shark and Flowers的更多相关文章

  1. Codeforces Round #341 (Div. 2) E. Wet Shark and Blocks dp+矩阵加速

    题目链接: http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test2 se ...

  2. Codeforces Round #341 Div.2 B. Wet Shark and Bishops

    题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC ...

  3. Codeforces Round #341 Div.2 A. Wet Shark and Odd and Even

    题意是得到最大的偶数和 解决办法很简单 排个序 取和 如果是奇数就减去最小的奇数 #include <cstdio> #include <cmath> #include < ...

  4. Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks

    题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k< ...

  5. Codeforces Round #341 (Div. 2)

    在家都变的懒惰了,好久没写题解了,补补CF 模拟 A - Wet Shark and Odd and Even #include <bits/stdc++.h> typedef long ...

  6. Codeforces Round #341 (Div. 2) ABCDE

    http://www.cnblogs.com/wenruo/p/5176375.html A. Wet Shark and Odd and Even 题意:输入n个数,选择其中任意个数,使和最大且为奇 ...

  7. Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese 数学

    D. Rat Kwesh and Cheese 题目连接: http://www.codeforces.com/contest/621/problem/D Description Wet Shark ...

  8. Codeforces Round #341 (Div. 2)B

    B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. Codeforces Round #341 (Div. 2)A

    A. Wet Shark and Odd and Even time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. C# 判断文件有没占用

    C# 判断文件有没占用 using System; using System.Collections.Generic; using System.Text; using System.Runtime. ...

  2. 记AppStore 被打回的经历

    在快驰已然有半年时间之久. 见证了“快货运”产品,在不断摧残的环境中成长着.  两个人,将一个产品亲手从无到有的构建,有过心酸.有过累和有过憔悴,但当“快货运”开始上APP store时,又让人觉得开 ...

  3. java类中成员的划分

  4. 浅谈大数据神器Spark中的RDD

    1.究竟什么是RDD呢? 有人可能会回答是:Resilient Distributed Dataset.没错,的确是如此.但是我们问这个实际上是想知道RDD到底是个什么东西?以及它到底能干嘛?好的,有 ...

  5. 《java小应用程序(Applet)和java应用程序(Application)分别编写的简单计算器》

    Application和Java Applet的区别.Java语言是一种半编译半解释的语言.Java的用户程序分为两类:Java Application和Java Applet.这两类程序在组成结构和 ...

  6. layer弹框

    官网http://layer.layui.com/ /!*如果是页面层*/layer.open({ type: 1, content: '传入任意的文本或html' //这里content是一个普通的 ...

  7. Longest Increasing Path in a Matrix -- LeetCode 329

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...

  8. HDU5950(矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:f(n) = f(n-1) + 2*f(n-2) + n^4,f(1) = a , f(2 ...

  9. BZOJ3669 (动态树)

    Problem 魔法森林 (NOI2014) 题目大意 给n个点,m条边的无向图,每条边有两个权值a,b. 求一条从1-->n的路径,使得这条路径上max(a)+max(b)最小.输出最小值即可 ...

  10. android view:手势

    一直认为android手势识别很是神奇,我们不分析复杂的手势,仅仅是针对上一次的基本事件的手势处理,分析GestureDetector的源码,来看一下到底手势事件是如何定义的. GestureDete ...