Codeforces Round #341 Div.2 C. Wet Shark and Flowers
题意: 不概括了..太长了..
额第一次做这种问题 算是概率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的更多相关文章
- 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 ...
- Codeforces Round #341 Div.2 B. Wet Shark and Bishops
题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数 由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y 然后每个数组中扫描重复数字k ans加上kC ...
- Codeforces Round #341 Div.2 A. Wet Shark and Odd and Even
题意是得到最大的偶数和 解决办法很简单 排个序 取和 如果是奇数就减去最小的奇数 #include <cstdio> #include <cmath> #include < ...
- Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks
题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k< ...
- Codeforces Round #341 (Div. 2)
在家都变的懒惰了,好久没写题解了,补补CF 模拟 A - Wet Shark and Odd and Even #include <bits/stdc++.h> typedef long ...
- Codeforces Round #341 (Div. 2) ABCDE
http://www.cnblogs.com/wenruo/p/5176375.html A. Wet Shark and Odd and Even 题意:输入n个数,选择其中任意个数,使和最大且为奇 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 通过Request对象对cookie的设置、获取
<html> <head></head> <body> <% request.setCharacterEncoding("UTF-8&q ...
- MYSQL 处理批量更新数据的一些经验。
首先,我们需要了解下MYSQL CASE EXPRESSION 语法. 手册传送门:http://dev.mysql.com/doc/refman/5.7/en/control-flow-functi ...
- sql case when then else end
我们都知道SQL中适用case when then来转化数据库中的信息 比如 select (case sex when 0 then '男' else '女' end) AS sex from st ...
- NVelocity用法(转)
每个人应该知道的NVelocity用法 NVelocity是一个基于.NET的模板引擎(template engine).它允许任何人仅仅简单的使用模板语言(template language)来 ...
- 使用checkbox做出radiobutton的效果
首先分别使用不同name的checkbox放在同一个tr的两个td内.并为他们设置onclick事件来改变点击后状态. php: str[info]="<table align='ce ...
- 2016 - 3 - 12 SQLite的学习之SQL语言入门
1.SQL语句的特点: 1.1 不区分大小写 1.2 每条语句以;结尾 2.SQL语句中常用关键字: select,insert,update,from,create,where,desc,order ...
- android.app.Activity阅读摘要,有时候会不会需要保持一些现场数据呢? 想让系统帮你退出到后台或者挂掉前做些前置保持工作吗,重点参考吧:
* * @param savedInstanceState If the activity is being re-initialized after * previously being shut ...
- SSH中,使用Filter拦截直接访问JSP页面!
话不多说,直接上代码 创建一个Filter类 package com.weibo.util; import java.io.IOException; import javax.servlet.Filt ...
- Impossible to load an image in xcassets on bundle
Impossible to load an image in xcassets on bundle up vote5down votefavorite 3 I need to include imag ...
- Gulp构建前端自动化项目
类似于Grunt,gulp是另一个同样功能很强大的前端项目自动化利器. 下面是项目的效果: