并不对劲的CF1245E&F:Cleaning Ladders
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的更多相关文章
- some problem
CF1257F Make Them Similar $solution:$ 折半搜索后考虑如何维护两个数组的和,可以将 $A$ 中每个数减 $A_1$ ,$B$ 中每个数被减 $B_1$ ,$map$ ...
- Mysql_以案例为基准之查询
查询数据操作
- CF1245E:Hyakugoku and Ladders
CF1245E:Hyakugoku and Ladders 题意描述: 给你一个\(10*10\)的矩阵,矩阵描述如下 最开始的时候你在左下角,你的目标是到达左上角. 你可以走路径或者爬梯子. 路径的 ...
- Good Bye 2015 F - New Year and Cleaning
F - New Year and Cleaning 这题简直是丧心病狂折磨王.. 思路:容易想到这样一个转换,把整个矩形一起移动,矩形移出去的时候相当于一行或者一列. 为了优化找到下一个消去的点,我先 ...
- 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 ...
- [cf 1245 F] Daniel and Spring Cleaning
题意: 求区间$[l,r]$内有多少有序数对$(a,b)$满足$a+b=a\bigoplus b$. $l,r\leq 10^9$. 题解: 有用的就一句话: 求区间内一元组可以一维容斥,同理求二元组 ...
- 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, ...
- codeforces 597div2 F. Daniel and Spring Cleaning(数位dp+二维容斥)
题目链接:https://codeforces.com/contest/1245/problem/F 题意:给定一个区间(L,R),a.b两个数都是属于区间内的数,求满足 a + b = a ^ b ...
- 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚
题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...
随机推荐
- 在树莓派4b上安装 ROS MELODIC 源码安装
按照以下步骤照做就可以了,很简单的,就是浪费一点点时间罢了.也可以退而求其次,买个树莓派3B+来玩,哈哈. Step 1: Install Dependecies and Download the P ...
- mysql.zip版本的安装教程
MySQL zip版本安装 一直以来都习惯了使用MySQL安装文件(.exe),今天下载了一个.zip版本的MySQL,安装过程中遇到了一些问题,如下: 1.在MySQL官网上(http://dev. ...
- 冲刺阶段——Day1
[成员分工及任务量] 成员 分工 任务量(小时) 王梓鸿 完成页面设计并编写输入输出图形界面,部分代码测试 20 童皓祯 编写注册和登录模块代码,部分代码测试 20 林郅聪 绘制燃尽图,程序功能整合及 ...
- .net core 修改 Identity/AspNetUsers 数据库
众所周知,.net core有一套完整的用户管理功能.使用它就能实现用户的管理及登录登出功能.现在问题来了,我们有时候需要添加一些字段,该怎么办呢?当然是修改他呀.修改方法参考链接:https://m ...
- arcgis python 参数验证
import arcpy class ToolValidator(object): """Class for validating a tool's parameter ...
- C++的精髓——代码复用、接口复用
C++的精髓——代码复用.接口复用 在另一篇文章中提到C++三大特点的核心概括,也写在这里吧.封装:信息隐藏继承:代码复用多态:面向对象C++并不是面向对象,它包容多种编程思想,如面向过程,面向对象, ...
- android ONVIF 组播探测在线摄像机
http://blog.csdn.net/ghostyu/article/details/8182516 Android的Wifi,默认情况下是不接受组播的,见:http://developer.an ...
- Redis有序Set、无序Set的使用经历
为了实现一个类似关系数据库中的卖家信息的单表,首先我们知道单表必然可增删查改,其次为了区分先来后到又需要有ID主键且自增长.开始考虑使用hash数据类型,因为hash是key+列1.列2...这样一来 ...
- mvc 接收json 集合 实例
开始测试了一下,后台用实体类接收,所报异常如下 无奈之下只能传为字符串,然后字符串转json 页面代码如下 后台controller如下:
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...