CF 963E Circles of Waiting

2023-05-16

          • 传送门
          • 题目大意
          • 思路
          • 参考代码

传送门
题目大意

在平面直角坐标系上,有一个神奇的点,一开始在 (0,0) ( 0 , 0 ) 。每秒钟这个点都会随机移动:如果它在 (x,y) ( x , y ) ,下一秒它在 (x1,y) ( x − 1 , y ) 的概率是 p1 p 1 ,在 (x,y1) ( x , y − 1 ) 的概率是 p2 p 2 ,在 (x+1,y) ( x + 1 , y ) 的概率是 p3 p 3 ,在 (x,y+1) ( x , y + 1 ) 的概率是 p4 p 4 。保证 p1+p2+p3+p4=1 p 1 + p 2 + p 3 + p 4 = 1 ,各次移动互不关联。

求出这个点移动至距离原点距离大于 R(R50) R ( R ≤ 50 ) 的点的期望步数。距离为欧几里得距离。结果对 109+7 10 9 + 7 取模。

思路

  唉,我太弱了,什么都不会,这道题这么显然需要解方程,但我还是不会做。

  显然有:

fx,y=p1fx1,y+p2fx,y1+p3fx+1,y+p4fx,y+1+1 f x , y = p 1 ⋅ f x − 1 , y + p 2 ⋅ f x , y − 1 + p 3 ⋅ f x + 1 , y + p 4 ⋅ f x , y + 1 + 1

  总共有 R2 R 2 个点,因此我们立即得到一个 O(R6) O ( R 6 ) 的算法(此处 R R 100),然后 T 掉。


  感性地理解, fx,y f x , y 有系数的方程并不会太多,而且有系数的一定与它相邻。假设我们从上往下,从左往右编码,则有系数的项距自己的编码不会超过 2r 2 r ,因此整个方程组对应的增广矩阵大概长这样:

  对于每行,只需要在一个红框内消元即可:

  红框的大小为 2R 2 R ,因此时间复杂度为 O(R4) O ( R 4 )

参考代码
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cctype>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <list>
#include <functional>
typedef long long LL;
typedef unsigned long long ULL;
using std::cin;
using std::cout;
using std::endl;
typedef int INT_PUT;
INT_PUT readIn()
{
    INT_PUT a = 0; bool positive = true;
    char ch = getchar();
    while (!(ch == '-' || std::isdigit(ch))) ch = getchar();
    if (ch == '-') { positive = false; ch = getchar(); }
    while (std::isdigit(ch)) { a = a * 10 - (ch - '0'); ch = getchar(); }
    return positive ? -a : a;
}
void printOut(INT_PUT x)
{
    char buffer[20]; int length = 0;
    if (x < 0) putchar('-'); else x = -x;
    do buffer[length++] = -(x % 10) + '0'; while (x /= 10);
    do putchar(buffer[--length]); while (length);
}

const int mod = int(1e9) + 7;
const int maxn = 55;
int r;
int p1, p2, p3, p4;
int sum;

inline int code(int x) { return x + 50; }
inline double dis(int x, int y) { return std::sqrt(std::pow(x, 2) + std::pow(y, 2)); }
std::vector<std::pair<int, int> > pt;
int idx[maxn * 2][maxn * 2];
#define IDX(x, y) idx[code(x)][code(y)]

LL power(LL x, int y)
{
    LL ret = 1;
    while (y)
    {
        if (y & 1) ret = ret * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ret;
}

int rect[8000][8000];

void Gauss()
{
    int d = r * 2;
    for (int i = 1; i <= pt.size(); i++)
    {
        LL inv = power(rect[i][i], mod - 2);
        for (int j = i + 1, to1 = 0; j <= pt.size() && to1 <= d; j++, to1++)
        {
            LL ratio = inv * rect[j][i] % mod;
            if (ratio)
            {
                for (int k = i, to2 = 0; k <= pt.size() && to2 <= d; k++, to2++)
                    rect[j][k] = ((LL)rect[j][k] - rect[i][k] * ratio) % mod;
                rect[j][0] = ((LL)rect[j][0] - rect[i][0] * ratio) % mod;
            }
        }
    }

    for (int i = pt.size(), to = IDX(0, 0); i >= to; i--)
    {
        LL inv = power(rect[i][i], mod - 2);
        int& t = rect[i][0];
        t = inv * t % mod;
        for (int j = i - 1; j >= to; j--)
            rect[j][0] = (rect[j][0] - (LL)rect[j][i] * t) % mod;
    }
}

void solve()
{
    for (int x = r; x >= -r; x--)
        for (int y = -r; y <= r; y++)
            if (dis(x, y) <= r)
            {
                pt.push_back(std::make_pair(x, y));
                IDX(x, y) = pt.size();
            }

    for (int x = r; x >= -r; x--)
        for (int y = -r; y <= r; y++)
            if (int f = IDX(x, y))
            {
                rect[f][f] = -1;
                if (int t = IDX(x - 1, y))
                    rect[f][t] = p1;
                if (int t = IDX(x, y - 1))
                    rect[f][t] = p2;
                if (int t = IDX(x + 1, y))
                    rect[f][t] = p3;
                if (int t = IDX(x, y + 1))
                    rect[f][t] = p4;
                rect[f][0] = -1;
            }

    Gauss();
    printOut((rect[IDX(0, 0)][0] + mod) % mod);
}

void run()
{
    r = readIn();
    p1 = readIn();
    p2 = readIn();
    p3 = readIn();
    p4 = readIn();
    sum = ((LL)p1 + p2 + p3 + p4) % mod;
    LL inv = power(sum, mod - 2);
    p1 = (LL)p1 * inv % mod;
    p2 = (LL)p2 * inv % mod;
    p3 = (LL)p3 * inv % mod;
    p4 = (LL)p4 * inv % mod;
    solve();
}

int main()
{
    run();
    return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CF 963E Circles of Waiting 的相关文章

  • LaTeX 009:自定义带有 * 号的命令

    LaTeX 中 xff0c 我们经常见到 section 和 section xff0c 分别表示有编号的 section 和没有编号的 section 我们也想自己定义带有 号的命令 xff0c 但写下面的代码时却报错了 xff1a ne
  • 2022 New Year‘s Resolution

    Some Might Say 2022 New Year 39 s Resolution Some might say we are on the edge of the new era Always are they saying thi
  • C++ 多线程编程导论(中)

    受篇幅限制 xff0c 上半部分不再更新 xff0c 填坑的新内容都放在此文章中 文章目录 参考资料线程安全 xff08 续 xff09 互斥访问 互斥体 xff08 mutex xff09 和锁 xff08 lock xff09 什么是互
  • C++ 使用模板序列化/反序列化固定键值对

    仅是一个原型 xff0c 留作记录 我感觉可以写出非常逆天的代码 span class token macro property span class token directive hash span span class token d
  • 编译原理习题两则(龙书,写出语言的正则定义)

    3 3 5 3 注释 xff0c 即 和 之间的串 xff0c 且串中没有不在双引号 xff08 34 xff09 中的 注 xff1a 假设双引号是匹配的 思路 xff1a 从空串开始写 xff0c 写出整体框架后 xff0c 通过分类讨
  • 2023 New Year‘s Resolution

    This Is Game 2023 New Year 39 s Resolution My 2022 ended with a day of game I am convinced that I am not to blame becaus
  • 补录:2018 和 2019 New Year‘s Resolution

    前言 xff1a 吉光片羽 xff0c 以飨读者 2018 New Year 39 s Resolution One year and a half ago I felt that life in 2020 would be quite d
  • 原博文地址

    由于账号问题 xff0c 现更改为这个账号 xff0c 以下为原博文地址 使用WH MOUSE LL钩子来判断按键是否是mouse event模拟的 http blog csdn net qq 26140973 article detail

随机推荐

  • [NOI 2003] 文本编辑器 Splay 维护序列 / 块状链表

    传送门 xff08 JZOJ xff09 xff08 第一道全国决赛题 xff09 解法 1 xff1a 使用 Splay 维护 不管怎么说 xff0c 总和刚刚学过的迎合上了 这道题可以直接上 Splay 维护线性序列 xff0c 光标位
  • 一次macOS的升级填坑(macOS Catalina - macOS Monterey)

    目录 小序一 升级前操作二 升级中三 问题填坑1 像我一样长时间卡在一个进度条怎么办2 在更新途中重启过电脑 xff08 完整流程填坑 xff09 3 安装之后不能开机 xff0c 如何紧急拷贝资料4 安装不成功 xff0c 如何重新安装系
  • CF 713C Sonya and Problem Wihtout a Legend

    文章目录 传送门题目大意正解通过维护关键点来维护信息参考代码 传送门 题目大意 给定一个长度为 n n 3000
  • Luogu 3642 [APIO 2016] 烟火表演

    传送门引例 xff08 上一道题 xff09 凸函数一开始的思路正解参考代码总结 传送门 引例 xff08 上一道题 xff09 凸函数 回忆我们上一道题是怎么做的 我们维护的东西的实质是一个 xff08 下 xff09 凸函数 由于我们的
  • Luogu 3631 [APIO 2011] 方格染色

    传送门思路参考代码细节 传送门 思路 很不错的一道题 xff0c 用到的东西不深 xff0c 但是要想到确实需要一定思维 一开始我想的是动态规划 xff0c 发现如果要设状态需要知道一个格子左边 xff0c 上边和左上边三个格子的状态 然后
  • Luogu 3632 [APIO 2011] 寻路

    传送门正解参考代码 传送门 正解 暴力连边跑最短路就好了 xff0c 只不过代码太长太难写啦 xff01 参考代码 span class hljs preprocessor include lt cstdio gt span span cl
  • Luogu 3634 [APIO 2012] 守卫

    传送门思路正解参考代码 传送门 思路 感觉自己越来越笨了 首先 xff0c 很明显这道题需要把没有看到忍者的区间给删去 xff0c 可以用前缀和 O n O n 处理 xff0c 然后对没有删去的地方重新标号 重新标号时 xff0c 需要对
  • Luogu 1552 [APIO 2012] 派遣

    传送门思路参考代码 传送门 思路 唉 xff0c 我太弱了 xff0c 什么都不会 xff0c 题读错了两次 xff0c 一开始读成了一个一般的背包 xff0c 然后读成了一个价值和花费相同的背包 xff0c 最后才发现原来是一个价值为 1
  • 贪玩 CF 之旅

    文章目录 CF 7D Palindrome Degree http codeforces com problemset problem 7 D 题解 CF 713C Sonya and Problem Wihtout a Legend ht
  • Luogu 3638 [APIO 2013] 机器人

    传送门思路正解参考代码关于 SPFA 传送门 思路 n n 这么小 会不会是搜索题 稍有经验的我直接否定了这个结论 仔细读题并分析样例 发现原来一个位置可以有多个机器人 且机器人行走的时候无视其它机器人 那这个就是一张图啊 可以将这张图预处
  • Luogu 3647 [APIO 2014] 连珠线

    传送门思路参考代码 传送门 思路 唉 xff0c 我太弱了 xff0c 又看错题了 题目中说一个新的珠子和一个已经添加的珠子连接起来 xff0c 我没有看到 xff0c 然后就凉了 立个 flag xff1a 已经连续看错五题了 xff0c
  • 【转】mingw64的安装方法

    转自 xff1a http write blog csdn net postlist mingw64的安装方法 1 下载ming w64 http sourceforge net projects mingw w64 files or x8
  • Luogu 3645 [APIO 2015] 雅加达的摩天楼

    传送门思路正解参考代码Update 传送门 思路 唉 xff0c 我太弱了 xff0c 我都看出来要分块了 xff0c 就是做不来 不过终于把题读对了 先来看子任务三怎么做 显然可以有一个 O m 2 O m 2
  • Luogu 3644 [APIO 2015] 八邻旁之桥

    传送门思路当 k 61 2 时参考代码 传送门 思路 唉 xff0c 我太弱了 xff0c 什么都不会 xff0c 题也做不来 很明显这道题先要把不过河的人排除了 xff0c 剩下的都是要过河的 当 k 61 1 k 61 1 时 xff0
  • Luogu 3646 [APIO 2015] 巴厘岛的雕塑

    传送门总结 APIO 2015思路参考代码总结 传送门 总结 APIO 2015 争取今天做完一套 QAQ T1 我最多之能想到从高位向低位做 xff0c 然后就完全不会了 xff1b T2 我想到了分情况讨论 xff0c 但是没有建图成功
  • UOJ 2016 [APIO 2016] Gap

    传送门思路参考代码交互题 交互题大致形式Windows 平台下 xff08 Dev C 43 43 xff09 Ubuntu 平台下 传送门 思路 唉 xff0c 我太弱了 xff0c 什么都不会 xff0c 题也做不来 这道题简直就是利用
  • CF 940F Machine Learning

    传送门题目大意思路参考代码Remarks 传送门 题目大意 给你一个数组 a 1 n n 10 5 a 1 n
  • CF 976D Degree Set

    传送门题目大意思路参考代码总结 传送门 题目大意 给你一个长度为 n n 的正整数序列 d 1 d 2 d n d1 d2 dn xff08 d 1 lt d 2 lt lt d n
  • Luogu 3778 [APIO 2017] 商旅

    传送门思路参考代码 传送门 思路 唉 xff0c 我太弱了 xff0c 什么都不会 看到这道题就想到了二分答案找负环 xff0c 但是怎么做呢 xff1f 完全不会 唉 xff0c 我太弱啦 xff01 先注意题目中说可以重复经过点和边 x
  • CF 963E Circles of Waiting

    传送门题目大意思路参考代码 传送门 题目大意 在平面直角坐标系上 xff0c 有一个神奇的点 xff0c 一开始在 0 0 0 0 每秒钟这个点都会随机移动 xff1a 如果它在 x y