并不对劲的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;
}

原文地址:https://www.cnblogs.com/xzyf/p/11785382.html

时间: 2024-08-30 17:06:51

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

过分过分进货价获国家

http://f.dangdang.com/group/24554/3491082/http://f.dangdang.com/group/24554/3491087/http://f.dangdang.com/group/24554/3491094/http://f.dangdang.com/group/24554/3491099/http://f.dangdang.com/group/24554/3491105/http://f.dangdang.com/group/24554/349111

我们找个地方看好戏

http://v.qq.com/page/f/y/4/m041433ssun.html http://v.qq.com/page/f/y/4/m041433ssun.html http://v.qq.com/page/f/y/4/m04143o3lhg.html http://v.qq.com/page/f/y/4/m04144675h3.html http://v.qq.com/page/f/y/4/m04144k1k1j.html http://v.qq.com/page/f/y/4/m04

CF1245E:Hyakugoku and Ladders

CF1245E:Hyakugoku and Ladders 题意描述: 给你一个\(10*10\)的矩阵,矩阵描述如下 最开始的时候你在左下角,你的目标是到达左上角. 你可以走路径或者爬梯子. 路径的定义: 如果当前在一行的最右边,你可以网上爬一格. 如果在行内其他位置,你可以往旁边走. 每一回合你都要掷一个六面的骰子,假设当前骰子的正面为\(r\).如果到终点的距离小于\(r\),那么你将不能移动.否则你将移动\(r\)格,如果你最后移动到的位置有一个梯子,你可以选择爬上去或者不怕上去. 你的

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,r)-2F(l-1,r)+F(l-1,l-1)$ 意思就是总方案减去 $a,b$ 至少一个数小于 $l$ 再加上 $a,b$ 都小于 $l$ 的方案 然后现在考虑求 $F$ 首先显然 $a+b=a \text{ xor } b$ 意思就是二进制下不存在同时为 $1$ 的位 那么可以考虑简单的数位 $

POJ - 2564 Edit Step Ladders

题意:题目按字典序给你多个字符串,判断如果一个字符串通过加,减,变一个字母的情况下可以变成另一个字符串的话,就代表他们之间有一个阶梯,求最多的阶梯 思路:首先我们应该想到这个有点LIS的感觉,然后我们可以采用记忆化搜索,然后就是每当一个字符串进行相应的变化后就去查找后面是否有这个字符串,依次找下去,判断最大值,重点是要通过HASH来优化 #include <iostream> #include <cstdio> #include <cstring> #include &

Coursera-Getting and Cleaning Data-week1-课程笔记

Coursera-Getting and Cleaning Data-week1 Sunday, January 11, 2015 课程概述 Getting and Cleaning Data是Coursera数据科学专项的第三门课,有中文翻译.但是由于中文区讨论没有英文区热闹,以及资料积累,强烈建议各位同时选报中文项目和英文项目,可以互相匹配学习. Week1的课程概括下来,主要介绍了getting and cleaning data的目的,即从不同数据源里获得整洁数据集(Tidy Data)

[BZOJ1672][Usaco2005 Dec]Cleaning Shifts 清理牛棚

1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 953  Solved: 407 [Submit][Status][Discuss] Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require the

POJ - 2376 Cleaning Shifts 贪心(最小区间覆盖)

Cleaning Shifts Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some cleaning chores around the barn. He always wants to have one cow working on cleaning things up and has divided the day into T shifts (1 <= T <= 1,000,000

POJ - 2688 Cleaning Robot

题意:求回收所有垃圾的最短路 思路:先BFS处理两个垃圾的距离,然后DFS记忆化搜索 dp[i][state]表示处理到第i个后状态是state的最短路 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> using namespace std; const int