题意:二维平面上右一点集\(S\),共\(n\)个元素,开始位于平面上任意点\(P\),\(P\)不一定属于\(S\),每次操作为选一条至少包含\(S\)中两个元素和当前位置\(P\)的直线,每条直线选取概率相同,同一直线上每个点\(Q \in S\) 选取概率相同,\(Q\)次询问 包含两个元素\(t,m\) 即点\(P\)到\(t\)共操作\(m\)次的最大概率

打了场\(CF\) 结果\(D\)题死活调不出来 只能一大早来补题了

可以想到记录\(f[i][j][k]\)表示从点\(i\)到点\(j\)走\(k\)步的概率 这个过程我们可以通过记录\(2^x\)的矩阵来存储

之后可以发现对于一个询问\(t,m\) 我们可以通过矩阵的转移得到走\(m-1\)步的答案 之所以不能直接走\(m\)步是因为第一步的点P不一定在\(S\)内 分析一下就可以发现 一条线\(l\)上的点的概率就\(\frac {\sum_{(i \in S)}probility[i]}{\sum_{(i \in S)}1}\) 对所有直线取个\(max\)就是答案了

复杂度 \(O((n + q) \cdot n^2 \cdot \log m)\)

#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pa pair<int,int>
#define mod 1000000007
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define cl(x) memset(x,0,sizeof x)
#ifdef Devil_Gary
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define bug(x)
#define debug(...)
#endif
const int INF = 0x7fffffff;
const int N=2e2+5;
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
inline int read(){
int x=0,rev=0,ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')rev=1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return rev?-x:x;
}
int n,flg,x[N],y[N];
double ans,pro[N],tmp[N];
vector<vector<int> > lines;
struct matrix{
double g[N][N];
matrix operator * (const matrix&a){
matrix c;cl(c.g);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
for(int k=0;k<n;k++)
c.g[i][j]+=g[i][k]*a.g[k][j];
return c;
}
}f[15];
pa fix(pa a){
if(a.fi==0) return mk(0,1);
if(a.se==0) return mk(1,0);
int d=__gcd(a.fi,a.se);
a.fi/=d,a.se/=d;
if(a.fi<0) a.fi*=-1,a.se*=-1;
return a;
}
void add(int p){
map<pa ,vector<int>>cnt;
for(int i=0;i<n;i++) if(i!=p){
int dx=x[i]-x[p],dy=y[i]-y[p];
cnt[fix(mk(dx,dy))].pb(i);
}
int sz=cnt.size();
for(auto u:cnt){
u.se.pb(p),flg=1;
for(auto v:u.se){
f[0].g[p][v]+=1.0/u.se.size()/sz;
if(v<p) flg=0;
}
if(flg) lines.pb(u.se);
}
}
int main(){
#ifdef Devil_Gary
freopen("in.txt","r",stdin);
#endif
n=read();
for(int i=0;i<n;i++) x[i]=read(),y[i]=read();
for(int i=0;i<n;i++) add(i);
for(int i=1;i<=14;i++) f[i]=f[i-1]*f[i-1];
for(int Q=read();Q;Q--){
int t=read()-1,m=read()-1;
for(int i=0;i<n;i++) pro[i]=0;pro[t]=1.0;
for(int i=0;i<=14;i++){
if(m&(1<<i)){
for(int j=0;j<n;j++) tmp[j]=pro[j],pro[j]=0;
for(int j=0;j<n;j++) for(int k=0;k<n;k++){
pro[j]+=tmp[k]*f[i].g[j][k];
}
}
}
ans=0;
for(auto line:lines){
double temp=0;
for(auto u:line) temp+=pro[u];
ans=max(ans,temp/line.size());
}
printf("%.12lf\n",ans);
}
}

Codeforces 989E A Trance of Nightfall 矩阵快速幂+DP的更多相关文章

  1. Codeforces 576D Flights for Regular Customers 矩阵快速幂+DP

    题意: 给一个$n$点$m$边的连通图 每个边有一个权值$d$ 当且仅当当前走过的步数$\ge d$时 才可以走这条边 问从节点$1$到节点$n$的最短路 好神的一道题 直接写做法喽 首先我们对边按$ ...

  2. Codeforces Round #536 (Div. 2) F 矩阵快速幂 + bsgs(新坑) + exgcd(新坑) + 欧拉降幂

    https://codeforces.com/contest/1106/problem/F 题意 数列公式为\(f_i=(f^{b_1}_{i-1}*f^{b_2}_{i-2}*...*f^{b_k} ...

  3. codeforces 691E 矩阵快速幂+dp

    传送门:https://codeforces.com/contest/691/problem/E 题意:给定长度为n的序列,从序列中选择k个数(可以重复选择),使得得到的排列满足xi与xi+1异或的二 ...

  4. Codeforces 514E Darth Vader and Tree 矩阵快速幂

    Darth Vader and Tree 感觉是个很裸的矩阵快速幂, 搞个100 × 100 的矩阵, 直接转移就好啦. #include<bits/stdc++.h> #define L ...

  5. CodeForces 450B Jzzhu and Sequences(矩阵快速幂)题解

    思路: 之前那篇完全没想清楚,给删了,下午一上班突然想明白了. 讲一下这道题的大概思路,应该就明白矩阵快速幂是怎么回事了. 我们首先可以推导出 学过矩阵的都应该看得懂,我们把它简写成T*A(n-1)= ...

  6. codeforces 450B B. Jzzhu and Sequences(矩阵快速幂)

    题目链接: B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input ...

  7. Product Oriented Recurrence(Codeforces Round #566 (Div. 2)E+矩阵快速幂+欧拉降幂)

    传送门 题目 \[ \begin{aligned} &f_n=c^{2*n-6}f_{n-1}f_{n-2}f_{n-3}&\\ \end{aligned} \] 思路 我们通过迭代发 ...

  8. Codeforces 954 dijsktra 离散化矩阵快速幂DP 前缀和二分check

    A B C D 给你一个联通图 给定S,T 要求你加一条边使得ST的最短距离不会减少 问你有多少种方法 因为N<=1000 所以N^2枚举边数 迪杰斯特拉两次 求出Sdis 和 Tdis 如果d ...

  9. P1357 花园 (矩阵快速幂+ DP)

    题意:一个只含字母C和P的环形串 求长度为n且每m个连续字符不含有超过k个C的方案数 m <= 5  n <= 1e15 题解:用一个m位二进制表示状态 转移很好想 但是这个题是用矩阵快速 ...

随机推荐

  1. iPhone 收藏网址[添加到书签] 和 [添加到主屏幕] 显示自定义图标,而不是网页截图

    iPhone 收藏网址[添加到书签] 和 [添加到主屏幕] 显示自定义图标,而不是网页截图: <!-- Safari浏览器[添加到书签] --> <link rel="sh ...

  2. oracle instantclient_11_2插件安装

    1.安装plsql 2.instantclient_11_2下载,解压到目录 D:\DevTools\instantclient_11_2 3.打开plsql, 点击“取消” 4.选择“工具”--&g ...

  3. 破解idea

    2019最新注册码 地址:  http://idea.lanyus.com/ https://blog.csdn.net/best_luxi/article/details/81479820

  4. n个月后兔子的个数问题(for循环)

  5. rem布局加载闪烁问题

    说明:以下内容来自CSDN,如有侵权,请立刻联系博主(我),我将删除该内容. 原文链接  https://blog.csdn.net/u013778905/article/details/779387 ...

  6. pytest九:使用自定义标记 mark

    pytest 可以支持自定义标记,自定义标记可以把一个 web 项目划分多个模块,然后指定模块名称执行.app 自动化的时候,如果想android 和 ios 公用一套代码时,也可以使用标记功能,标明 ...

  7. for循环输出9~0

    示例 for(var i = 9; i>-1;i--){ println(i) } function println(a) { document.write(a+"<br> ...

  8. 2017-2018-2 20155225《网络对抗技术》实验八 Web基础

    2017-2018-2 20155225<网络对抗技术>实验八 Web基础 1.Web前端HTML 输入命令apachectl start打开apahce,并使用netstat -aptn ...

  9. <转>用 Java 技术创建 RESTful Web 服务

    转自:https://www.ibm.com/developerworks/cn/web/wa-jaxrs/#N1017E JAX-RS:一种更为简单.可移植性更好的替代方式 Dustin Amrhe ...

  10. 【APUE | 10】函数signal

    函数signal 函数signal介绍 typedef void (*sighandler_t)(int); sighandler_t signal(int signum, sighandler_t ...