并不对劲的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 ...
随机推荐
- 一、Linux的基础使用--登录、开关机与在线、命令的查询帮助
目录 一.Linux的基础使用 1.1 X Window 与命令行模式的切换 1.2 命令行模式下命令的执行 1.3 修改支持语系 1.4 基础命令的操作 1.5 几个重要的热键[Tab].[Ctrl ...
- MyBatis——特殊传参问题小结
近期在写系统报表API的时候遇到MyBatis中的一些特殊写法: 1. 传入两个参数(一般情况下我们更多的是传入一个对象或者map) public List<MarketVehicleModel ...
- mysql密码设置为空怎么办?
由于很多童鞋安装使用MySQL时,安装时没有设置密码,或者像我一样图省事设置密码为空,想为其设置新密码: 1.点击 开始------>运行----在弹出的对话框中输入cmd 如下图: 2.使用 ...
- Smarty的分页实现
Smarty中的分页有很多方法.1.使用Smarty的分页插件,如Pager,pagnition,sliding_page等,不过感觉都不是太好,几乎都有一些Bug.有兴趣试用和自己去改进的朋友可以看 ...
- test20190510
- yum搭建LAMP环境
LAMP=Linux+Apache(httpd)+Mysql(mariadb)+PHP Apache HTTP 服务器 2.4 文档:http://httpd.apache.org/docs/2.4/ ...
- maven编译正常,运行报错:中没有主清单属性
在pom.xml添加插件 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId&g ...
- 解决mosh: Nothing received from server on UDP port 60001 环境: centos7.1
主要问题在于有的教程使用iptables命令来开启对应端口, 但是centos7.1中虽然iptables仍然存在, 但是没有默认安装相关服务, 而是使用firewalld来管理防火墙. 所以我开始以 ...
- 蓝牙AT模式
一.蓝牙AT模式设置方式 在通电前按住蓝牙模块黑色按钮,接电,当蓝牙指示灯按每隔两秒闪烁一次时进入AT模式: 有3种设置方式: 1.默认设置 模块工作角色:从模式 串口参数:38400bit ...
- zepto手机拼音字母城市选择器代码
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content ...