CodeForces 441E(Codeforces Round #252 (Div. 2))
思路:dp[i][now][mark][len] i 表示当前第i 次now存的是后8位,mark为第9位为0还是1 len第九位往高位还有几位和第9位相等。 只存后8位的原因:操作只有200次每次都为加法的话后8位可以表示,如果为乘法第八位已知再加上第九位 和往前的长度已知,所以可以表示所有状态。
所存在问题就是 10 1111 1111 此时加上1之后 会变成 11 0000 0000 但这样并处影响结果 如果之后操作都为加法,只有200次,他不可能影响到前面的1, 乘法相当于左移也不会影响。所以前面的1 不可能作为答案。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include <iostream>
using namespace std;
double d[][][][];
int a[];
int main() {
int x, k, p, h = ;
memset(d, , sizeof(d));
memset(a, , sizeof(a));
scanf("%d%d%d", &x, &k, &p);
while (x) {
a[h++] = x %;
x /= ;
}
int now = ;
for (int i = ; i < ; ++i)
if (a[i])
now += ( << i); if (h < ) {
d[][now][][] = ;
} else {
int cnt = ;
for (int i = ; i < h; ++i) {
if (a[i] != a[i - ])
break;
cnt++;
}
d[][now][a[]][cnt] = ;
}
for (int i = ; i < k; ++i) {
for (int j = ; j <= ; ++j) {
for (int x = ; x <= ; ++x) {
if (j != ) {
d[i + ][j + ][][x] += d[i][j][][x] * ( - p) / 100.0;
d[i + ][j + ][][x] += d[i][j][][x] * ( - p) / 100.0;
} else {
d[i + ][][][x] += d[i][j][][x] * ( - p) / 100.0;
d[i + ][][][] += d[i][j][][x] * ( - p) / 100.0;
} if (j & ( << )) {
d[i + ][(j << ) % ][][] += d[i][j][][x] * p / 100.0;
d[i + ][(j << ) % ][][x + ] += d[i][j][][x] * p
/ 100.0;
} else {
d[i + ][(j << ) % ][][] += d[i][j][][x] * p / 100.0;
d[i + ][(j << ) % ][][x + ] += d[i][j][][x] * p
/ 100.0;
}
}
}
}
double sum=;
for(int i=;i<;++i)
{
for(int j=;j<;++j)
for(int x=;x<=;++x)
{
int now=i;
int cnt=;
while(now%==)
{
cnt++;
now/=;
}
sum+=d[k][i][j][x]*cnt;
}
}
for(int x=;x<=;++x)
sum+=d[k][][][x]*;
for(int x=;x<=;++x)
sum+=d[k][][][x]*(x+);
printf("%.10lf\n",sum); return ;
}
CodeForces 441E(Codeforces Round #252 (Div. 2))的更多相关文章
- Codeforces Round 252 (Div. 2)
layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round #252 (Div. 2) B. Valera and Fruits(模拟)
B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #252 (Div. 2) D
http://codeforces.com/problemset/problem/441/D 置换群的基本问题,一个轮换内交换成正常顺序需要k-1次,k为轮换内元素个数 两个轮换之间交换元素,可以把两 ...
- codeforces Round #252 (Div. 2) C - Valera and Tubes
贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #i ...
- Codeforces Round #252 (Div. 2) B. Valera and Fruits
#include <iostream> #include <vector> #include <algorithm> #include <map> us ...
- Codeforces Round #252 (Div. 2) A - Valera and Antique Items
水题 #include <iostream> #include <set> #include <vector> #include <algorithm> ...
- Codeforces Round #252 (Div. 2) 441B. Valera and Fruits
英语不好就是坑啊.这道题把我坑残了啊.5次WA一次被HACK.第二题得分就比第一题高10分啊. 以后一定要加强英语的学习,要不然就跪了. 题意:有一个果园里有非常多树,上面有非常多果实,为了不然成熟的 ...
- Codeforces Round #252 (Div. 2)-C,D
C题就是一个简单的模拟.首先给每一个人两个.然后把剩下的都给一个人就好了. 给的时候蛇形给. #include<stdio.h> #include<string.h> #inc ...
- 【Codeforces AIM Tech Round 4 (Div. 2) C】
·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意: 输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...
随机推荐
- [转载] zookeeper 事件通知
ZK事件回调当一个client访问ZK时,client与ZK保持长连接.应用可以通过client的api注册一些callback,当对应的事件发生时,client会执行对应的callback.如果你基 ...
- UML建模
1.包含<<include>> 包含是指当多个用例中存在相同的事件流时,可以把这些公共事件流抽象成公共用例,这个公共用例称之为抽象用例(跟类的概念有点相像,类是多个对象的抽象定 ...
- iOS开发之Xcode 6更新默认不支持armv7s架构
最近一次的Xcode 6更新默认不再支持arm7s架构,究竟是要废除不用呢还是仅仅只是一个疏忽? 目前的Xcode 6配置里定义${ARCHS_STANDARD}为armv7, arm64,当然这个定 ...
- JQuery $()后面的括号里的内容什么时候加引号,什么时候不加
一.如果是已经声明存在的变量或者对象,就不用加引号. 比如var name=document.getElementById("name"); $(name)或者$(this). 二 ...
- jquery 获取鼠标位置
//获取鼠标位置 $(function(){ $('body').mousemove(function(e) { e = e || window.event; __xx = e.pageX || e. ...
- 转!! Java中如何遍历Map对象的4种方法
在Java中如何遍历Map对象 How to Iterate Over a Map in Java 在java中遍历Map有不少的方法.我们看一下最常用的方法及其优缺点. 既然java中的所有map都 ...
- 转!!Java JTable 根据表格内容 自动调整表格列宽
//根据表格内容 自动调整列宽http://blog.sina.com.cn/s/blog_5e54d6140100s1d3.html
- android UI库
https://github.com/wasabeef/awesome-android-ui List of Android UI/UX Libraries A curated list of awe ...
- LocalStorage在Chrome里的实现
前段时间我们在实现CanTK-Runtime时,也曾在V8基础上模拟过浏览器的LocaleStorage功能,其实现非常简单:每个domain的数据使用的单独文件存储,因为同一时间只有一个游戏运行,所 ...
- 解决 placeholder 垂直不居中,偏上的问题
解决 placeholder 垂直不居中,偏上的问题 安卓浏览器显示placeholder 垂直不居中,而iphone没问题,搜了一下答案,解决方法是把input的line-height去掉就行 参考 ...