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<= ...
随机推荐
- (三)结构体指针、sizeof
(一)结构体指针定义 今天上班写了一段测试代码,结果在linux下编译出现段错误,刚开始一直找不到原因,后来找了度娘才搞懂了.我先贴出来第一次写的代码以及gcc编译器下报的错误: #include&l ...
- linux 多线程信号处理总结
linux 多线程信号总结(一) 1. 在多线程环境下,产生的信号是传递给整个进程的,一般而言,所有线程都有机会收到这个信号,进程在收到信号的的线程上下文执行信号处理函数,具体是哪个线程执行的难以获知 ...
- zabbix监控系统客户端安装
原文:http://blog.chinaunix.net/uid-25266990-id-3387002.html 测试使用agentd监听获取数据. 服务端的安装可以查看http://blog.ch ...
- oracle 生成随机数【待整理】
http://www.cnblogs.com/ulex/p/4415478.html http://blog.sina.com.cn/s/blog_6a01140c0100wimi.html
- Java Date与SimpleDateFormat
最近在弄一些涉及到时间处理的项目.本来自己写了一个时间转换函数,虽然能用但是过于麻烦而且不够规范,于是学习了下java自带的时间处理的类. public class Timechg { public ...
- Android监听Button和ImageButton控件的点击事件
一.onClick事件 Button和ImageButton都有一个onClick事件,通过自身的.setOnClickListener(OnClickListener)方法添加点击事件 所有的控件都 ...
- SDL1.2到2.0的迁移指南(转)
里面有些单词不好翻译所以放在开头,以备查验. BLock Image Transfer, a computer graphics operation in which two bitmap patte ...
- css 颜色渐变
.top_nav { width: 100%; height: 29px; /* 如果浏览器不支持渐变,使用图像作为背景 */ background: u ...
- sql raiseerror
raiserror 的作用: raiserror 是用于抛出一个错误.[ 以下资料来源于sql server 2005的帮助 ] 其语法如下: RAISERROR ( { msg_id | msg ...
- SQL Server 2008 R2 开启允许远程连接
方法/步骤 1 登陆SQL Server 2008(windows身份认证),登陆后右击,选择“属性”. 2 左侧选择“安全性”,选中右侧的“SQL Server 和 Windows 身份验证 ...