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.若三种食物都有的情况,巧克力不能在中 ...
随机推荐
- Table of Contents - HttpClient
HttpClient 4.3.5 Getting Started HttpClient 简单示例 Fundamentals Request Execution HTTP Request & H ...
- DWZ (JUI) 教程 根据ID刷新 dialog
reloadDialog:function(dialogId){ var dialog = $("body").data(dialogId); if(dialog){ $.pdia ...
- ios卡牌游戏项目源码
上传者fu_sion,源码CardGame,一副牌从中抽取十二张牌,翻开牌可以相同的花色+1 相同的数字+4分 同一张牌翻开后可以盖上(算是一个BUG)就酱紫~~ 项目源码下载:http://code ...
- 使用MSBUILD 构建时出错 error MSB3086: Task could not find "sgen.exe" using the SdkToolsPath的解决方法
如果项目有添加有WB引用,比如引用其它网站的WEB服务等,那么VS在编译时会自动生成个 [项目名称].Serializers.dll的文件,就是把引用服务中的相关对象信息生成硬编码的程序集,以提高效率 ...
- Cocos2d-JS中的Sprite精灵类
精灵类是cc.Sprite,它的类图如下图所示.cc.Sprite类直接继承了cc.Node类,具有cc.Node基本特征. 创建Sprite精灵对象 创建精灵对象可以使用构造函数实现,它们接受相同的 ...
- UI4_LabelChess
// // AppDelegate.m // UI4_LabelChess // // Created by zhangxueming on 15/6/29. // Copyright (c) 201 ...
- linux 系统运行级别及修改[转]
Linux运行级别从0-6,共7个. 0:关机.不能将系统缺省运行级别设置为0,否则无法启动. 1:单用户模式,只允许root用户对系统进行维护. 2:多用户模式,但不能使用NFS(相当于Window ...
- java 自动装箱和自动拆箱
自动装箱 java执行Integer i = 100:编译器编译成Integer i = Integer.valueOf(100); Integer i = 100; //编译器编译成Integer ...
- ADO.NET笔记——使用DataAdapter执行增删改操作
相关知识: DataSet中的数据一旦从数据库下载下来,便不再与数据库保持联系.如果修改了DataSet中的数据,需要重新建立连接,并且通过SQL命令将修改更新到数据库去 编写SQL命令往往比较繁琐和 ...
- PHP性能优化-编译级别的缓存
最近安装了 php5.6,发现有了 opcache.so扩展文件,于是,搜索了一下,发现 zend opcache已经融入到 ph5.5以上的版本了,即兴奋,不用再去找xcache,apc,eAcce ...