bnuoj 16493 Just Pour the Water(矩阵快速幂)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=16493
【题解】:矩阵快速幂
【code】:
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <iostream>
using namespace std; int N;
struct matrix
{
double a[][];
}origin,res; matrix multiply(matrix x,matrix y)
{
matrix temp;
for(int i=;i<=N;i++)
{
for(int j=;j<=N;j++)
{
double ans=;
for(int k=;k<=N;k++)
{
ans+=x.a[i][k]*y.a[k][j];
}
temp.a[i][j]=ans;
}
} return temp;
} matrix calc(int n)
{
while(n)
{
if(n%==)
res=multiply(origin,res);
origin=multiply(origin,origin);
n/=;
}
return res;
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
N=n;
double x[];
int i,j;
for(i=;i<=n;i++)
{
scanf("%lf",&x[i]);
}
memset(origin.a,,sizeof(origin.a));
for(i=;i<=n;i++)
{
int k;
scanf("%d",&k);
if(k==) origin.a[i][i]=1.0;
for(j=;j<=k;j++)
{
int p;
scanf("%d",&p);
origin.a[p][i]=1.0/k;
}
}
memset(res.a,,sizeof(res.a));
for(i=;i<=n;i++)
{
res.a[i][i]=;
}
int m;
scanf("%d",&m);
calc(m);
for(i=;i<=n;i++)
{
double ans=;
for(j=;j<=n;j++)
{
ans+=res.a[i][j]*x[j];
}
if(i==)
{
printf("%.2lf",ans);
}
else
{
printf(" %.2lf",ans);
}
}
putchar(); }
return ;
}
bnuoj 16493 Just Pour the Water(矩阵快速幂)的更多相关文章
- zoj 2974 Just Pour the Water矩阵快速幂
Just Pour the Water Time Limit: 2 Seconds Memory Limit: 65536 KB Shirly is a very clever girl. ...
- ACM-ICPC 2018 焦作赛区网络预赛 L:Poor God Water(矩阵快速幂)
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- zoj 2974 Just Pour the Water (矩阵快速幂,简单)
题目 对于案例的解释请见下图: 这道要变动提取一下矩阵,之后就简单了 具体解释可看代码: #include <string.h> #include <stdio.h> #inc ...
- ZOJ 2794 Just Pour the Water 【矩阵快速幂】
给你n个杯子,每次有特定的到水规则,倒m次请问最后每个被子里还有多少水 我们很容易发现每次变化的规则相同,那么可以set 一个矩阵存放 然后多次倒水就相当于矩阵相乘,在m 范围达到(1<= M ...
- bnuoj 34985 Elegant String DP+矩阵快速幂
题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 We define a kind of strings as elegant s ...
- ACM-ICPC 2018 焦作赛区网络预赛- L:Poor God Water(BM模板/矩阵快速幂)
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- 焦作网络赛L-Poor God Water【矩阵快速幂】
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- dutacm.club Water Problem(矩阵快速幂)
Water Problem Time Limit:3000/1000 MS (Java/Others) Memory Limit:163840/131072 KB (Java/Others)Tot ...
- ACM-ICPC 2018 焦作赛区网络预赛 L Poor God Water(矩阵快速幂,BM)
https://nanti.jisuanke.com/t/31721 题意 有肉,鱼,巧克力三种食物,有几种禁忌,对于连续的三个食物:1.这三个食物不能都相同:2.若三种食物都有的情况,巧克力不能在中 ...
随机推荐
- php中一串数子的转化
echo "<meta charset=utf-8>"; echo "笔试题测试"; $str = "123456780"; $ ...
- $(function(){})与$(document).ready(function(){})
$(function(){ //jq ready()的简写 }); $(document).ready(function(){ // }); 或者: $().ready(function(){ //j ...
- MongoDB - MongoDB CRUD Operations, Query Documents, Project Fields to Return from Query
By default, queries in MongoDB return all fields in matching documents. To limit the amount of data ...
- CSS3--实现特殊阴影 (实例)
学习来源:慕课网http://www.imooc.com/view/240 先看效果图↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ HTML结构 <body> <div class=& ...
- PHP中变量,常量,超级全局变量小结
//一般来说,变量在函数无法在函数体中无法访问,但是常量可以.//超级全局变量确实可以的,地址栏上的参数/*$GLOBALS //变量注册的信息$_GET //地址栏参数$_POST ...
- Javascript之数据执行原理探究
Javascript在Web服务器端执行原理: 1.客户端请求数据,即我们在上网时在地址栏中输入某个网址,浏览器接收到数据之后,向远程web服务器发送请求报文. 2.web服务器响应请求,web服务器 ...
- Dos下查询关闭端口的命令例子
1. 查看端口占用 在windows命令行窗口下执行: netstat -aon|findstr "8080" TCP 127.0.0.1:80 0.0.0 ...
- jQuery AJAX Call for posting data to ASP.Net page ( not Get but POST)
the following jQuery AJAX call to an ASP.Net page. $.ajax({ async: true, type: "POST", url ...
- maxlength属性在textarea里奇怪的表现
HTML5给表单带来了很多改变,比如今天要说的maxlength,这个属性可以限制输入框输入的最大字字符数,更方便的是对于粘贴的内容也能够根据字符数自动截断. 最近就接到这要一个需求,限制用户最多输入 ...
- The New Debugger
在debug下有一个中文叫做杂项的选项卡下有配置的内容 里面可以配置debug的模式 有的时候一些莫名其妙的问题需要 调整里面的设置 <<SAP debug的几种方式.pdf>> ...