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<= ...
随机推荐
- [玲珑OJ1044] Quailty and Binary Operation (FFT+cdq分治)
题目链接 题意:给定两个长度为n的数组a与长度为m的数组b, 给定一个操作符op满足 x op y = x < y ? x+y : x-y. 有q个询问,每次给出询问c,问:有多少对(i, j ...
- bootstrap 图片轮播效果
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="http: ...
- count-the-repetitions
https://leetcode.com/problems/count-the-repetitions/ 下面是我的方法,结果对的,超时了... package com.company; class ...
- Swift语言学习之学习资源
(1) http://swift.sh (2) Let's Swift – WRITE THE CODE. CHANGE THE WORLD. http://letsswift.com (3)http ...
- asmca无法创建ASM磁盘
现象 grid用户使用asmca无法创建asm磁盘,如下图 分析 如图所示,报错说是 Grid Infrastructure 出了问题.那么 Grid Infrastructure 是什么 ? 在安装 ...
- MapReduce工作原理
第一部分:MapReduce工作原理 MapReduce 角色•Client :作业提交发起者.•JobTracker: 初始化作业,分配作业,与TaskTracker通信,协调整个作业.•Tas ...
- LTIB常用命令1
下面再写一点ltib的常用命令参数吧,虽然觉得对其编译内核和文件系统流程有了一定了解,但是对其命令参数用过的还不是很多,可以说是不甚了解,下面介绍一些,希望有用: 首先一个比较有用的命令参数就是hel ...
- hiho_1290_demo_day
题目大意 一个MxN的矩阵,矩阵中的有些方格中有障碍物,有些没有,有一个机器人从左上角出发,它只能有两种移动方式:一直向右移动,直到遇到障碍物:一直向下移动,直到遇到障碍物. 现在可以将矩阵中 ...
- No resource found that matches the given name 'Theme.AppCompat.Light'
eclipse在新建andorid工程的时候出现找不到AppCompat.Light主题的问题,这是因为缺少支持低版本的v7包所致, 这个不是jar包,在sdk的extras->andorid- ...
- ListView配合BaseAdapter
BaseAdapter使用比较麻烦,它是个抽象类,需要重写4个方法分别是getCount() getItem(..) getItemId(..) getVew(..),相应的使用BaseAdapter ...