CF1245 E. Hyakugoku and Ladders

题目大意

有一个10 \(\times\) 10的网格,你要按这样的路径行走:

网格中有一些单向传送门,每个传送门连接的两个格子在同一列。传送门的方向一定是从下往上的,而且每个格子的出度至多为1,最上面一行的格子没有出去的传送门。

你的行走步骤是这样:

1.抛一枚六面骰子,如果往前走点数步不会走超过终点就往前走点数步,反之站着不动并且跳过第二步;

2.如果这一点有传送门,可以选择进传送门或不进。

在恰好走到终点上之前,你会不断重复以上两步。

求在用最优策略进传送门时,期望重复以上步骤多少次。

题解

设\(f(i,j)\)表示从坐标为\((i,j)\)的格子走到终点期望几次。

按题意模拟。

代码
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#define LL long long
#define D double
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
#define dwn(i,x,y) for(int i=(x);i>=(y);--i)
#define view(u,k) for(int k=fir[u];~k;k=nxt[k])
using namespace std;
int read()
{
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)&&ch!='-')ch=getchar();
if(ch=='-')f=-1,ch=getchar();
while(isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return x*f;
}
void write(int x)
{
char ch[20];int f=0;
if(!x){putchar('0'),putchar('\n');return;}
if(x<0)putchar('-'),x=-x;
while(x)ch[++f]=x%10+'0',x/=10;
while(f)putchar(ch[f--]);
putchar('\n');
}
D f[107];
int h[17][17],to[107],px[107],py[107],bac[17][17],cntp;
int main()
{
dwn(i,10,1)
{
if(!(i&1)){rep(j,1,10)cntp++,bac[i][j]=cntp;}
else {dwn(j,10,1)cntp++,bac[i][j]=cntp;}
}
rep(i,1,10)
rep(j,1,10)
{
h[i][j]=read();int x=i-h[i][j],y=j;
to[bac[i][j]]=bac[x][y];
}
f[100]=0;
dwn(i,99,1)
{
D tmp=1.0;int li=min(6,100-i);
if((100-i)<6)tmp=6.0/(100.0-(D)i),f[i]+=(6.0-(D)li)/6.0;
rep(j,1,li)
{
D x=min(f[i+j],f[to[i+j]]);
f[i]+=(x+1.0)/6.0;
}
f[i]*=tmp;
}
printf("%.10lf",f[1]);
return (0-0);
}

CF1245F. Daniel and Spring Cleaning

题目大意

给区间\([l,r]\),问有多少\(a\in[l,r],b\in[l,r]\)满足\(a\space xor \space b=a+b\)。

\(0\leq l\leq r\leq 10^9\)。

题解

设\(f(x,y)\)表示有多少\(a\in[0,x],b\in[0,y]\)满足\(a\space xor \space b=a+b\)。

答案=\(f(r,r)-2\times f(l-1,r)+f(l-1,l-1)\)。

计算\(f\)可以按二进制位数位dp。

代码
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define rep(i,x,y) for(register int i=(x);i<=(y);++i)
#define dwn(i,x,y) for(register int i=(x);i>=(y);--i)
#define view(u,k) for(int k=fir[u];~k;k=nxt[k])
#define LL long long
#define maxn 37
using namespace std;
int read()
{
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)&&ch!='-')ch=getchar();
if(ch=='-')f=-1,ch=getchar();
while(isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return x*f;
}
void write(LL x)
{
if(x==0){putchar('0'),putchar('\n');return;}
int f=0;char ch[20];
if(x<0)putchar('-'),x=-x;
while(x)ch[++f]=x%10+'0',x/=10;
while(f)putchar(ch[f--]);
putchar('\n');
return;
}
int t,l,r,a[maxn],b[maxn],len;
LL f[maxn];
LL getf(int i,int yes1,int yes2)
{
if(i==-1){return 1;}
if(f[i]!=-1&&yes1&&yes2)return f[i];
int li1=yes1?1:a[i],li2=yes2?1:b[i];
LL res=0;
res=getf(i-1,yes1|a[i],yes2|b[i]);
if(li1==1)res+=getf(i-1,yes1,yes2|b[i]);
if(li2==1)res+=getf(i-1,yes1|a[i],yes2);
if(yes1&&yes2)f[i]=res;
return res;
}
LL work(int x,int y)
{
if(x<0||y<0)return 0;
memset(f,-1,sizeof(f));
len=0;
while(((1ll<<(len+1))-1ll)<(LL)x)len++;
while(((1ll<<(len+1))-1ll)<(LL)y)len++;
rep(i,0,len)a[i]=(x&(1<<i))?1:0;
rep(i,0,len)b[i]=(y&(1<<i))?1:0;
return getf(len,0,0);
}
int main()
{
t=read();
while(t--)
{
l=read(),r=read();
write(work(r,r)-2ll*work(r,l-1)+work(l-1,l-1));
}
return 0;
}

一些感想

上紫了!!!

并不对劲的CF1245E&F:Cleaning Ladders的更多相关文章

  1. some problem

    CF1257F Make Them Similar $solution:$ 折半搜索后考虑如何维护两个数组的和,可以将 $A$ 中每个数减 $A_1$ ,$B$ 中每个数被减 $B_1$ ,$map$ ...

  2. Mysql_以案例为基准之查询

    查询数据操作

  3. CF1245E:Hyakugoku and Ladders

    CF1245E:Hyakugoku and Ladders 题意描述: 给你一个\(10*10\)的矩阵,矩阵描述如下 最开始的时候你在左下角,你的目标是到达左上角. 你可以走路径或者爬梯子. 路径的 ...

  4. Good Bye 2015 F - New Year and Cleaning

    F - New Year and Cleaning 这题简直是丧心病狂折磨王.. 思路:容易想到这样一个转换,把整个矩形一起移动,矩形移出去的时候相当于一行或者一列. 为了优化找到下一个消去的点,我先 ...

  5. Codeforces Round #597 (Div. 2) F. Daniel and Spring Cleaning 数位dp

    F. Daniel and Spring Cleaning While doing some spring cleaning, Daniel found an old calculator that ...

  6. [cf 1245 F] Daniel and Spring Cleaning

    题意: 求区间$[l,r]$内有多少有序数对$(a,b)$满足$a+b=a\bigoplus b$. $l,r\leq 10^9$. 题解: 有用的就一句话: 求区间内一元组可以一维容斥,同理求二元组 ...

  7. Codefroces 1245 F. Daniel and Spring Cleaning

    传送门 考虑简单的容斥 设 $F(n,m)$ 表示 $a \in [1,n] , b \in [1,m]$ 的满足 $a+b=a \text{ xor } b$ 的数对的数量 那么答案即为 $F(r, ...

  8. codeforces 597div2 F. Daniel and Spring Cleaning(数位dp+二维容斥)

    题目链接:https://codeforces.com/contest/1245/problem/F 题意:给定一个区间(L,R),a.b两个数都是属于区间内的数,求满足 a + b = a ^ b ...

  9. 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚

    题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...

随机推荐

  1. 【Python】使用Beautiful Soup等三种方式定制Jmeter测试脚本

    背景介绍 我们在做性能调优时,时常需要根据实际压测的情况,调整线程组的参数,比如循环次数,线程数,所有线程启动的时间等. 如果是在一台Linux机器上,就免不了在本机打开图形页面修改,然后最后传递到压 ...

  2. 安装Mysql-5.7.13脚本

    安装Mysql-5.7.13,此脚本最后会查找到临时密码,后面登进数据库中更改密码 [root@ZHONG-LONG javascripts]# vim -mysql.sh #!/bin/bash # ...

  3. SQL-W3School-高级:SQL DEFAULT 约束

    ylbtech-SQL-W3School-高级:SQL DEFAULT 约束 1.返回顶部 1. SQL DEFAULT 约束 DEFAULT 约束用于向列中插入默认值. 如果没有规定其他的值,那么会 ...

  4. 阶段5 3.微服务项目【学成在线】_day05 消息中间件RabbitMQ_9.RabbitMQ研究-工作模式-发布订阅模式-消费者

    消费者需要写两个消费者 定义邮件的类 复制以前的代码到邮件类里面进行修改 最上面 声明队列的名称和交换机的名称 监听修改为email 的队列的名称 手机短信接收端 复制一份email的接收端的代码 改 ...

  5. Qt编写数据可视化大屏界面电子看板6-窗体打开关闭

    一.前言 二级窗体的打开与关闭,这个功能也很有必要,由于整个系统中各种模块数量窗体数量比较多,后期可能还会增加更多,在4K屏幕上可以显示很多的模块,但是有时候有些模块不想显示出来,就需要将该模块关闭掉 ...

  6. linux安装IDEA 2017

    下载 IDEA 2017 链接:http://pan.baidu.com/s/1skTKdFR 密码:yug3 解压 下载的文件    tar zxvf idea-IU-172.4155.36.tar ...

  7. PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)

    1024 Palindromic Number (25 分)   A number that will be the same when it is written forwards or backw ...

  8. 阿里开源支持缓存线程池的ThreadLocal Transmittable ThreadLocal(TTL)

    功能 在使用线程池等会缓存线程的组件情况下,提供ThreadLocal值的传递功能. JDK的InheritableThreadLocal类可以完成父子线程值的传递. 但对于使用线程池等会缓存线程的组 ...

  9. Python生成随机数组的方法小结

    Python生成随机数组的方法小结 本文实例讲述了Python生成随机数组的方法.分享给大家供大家参考,具体如下: 研究排序问题的时候常常需要生成随机数组来验证自己排序算法的正确性和性能,今天把Pyt ...

  10. Goland 激活码

    实测有效,分享下 Goland