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.若三种食物都有的情况,巧克力不能在中 ...
随机推荐
- 304 CORS
304响应, CORS问题: 没有 Access-Control-Allow-Origin 这个头信息时,以前次返回的200请求为准. 示例:可能已被删除 http://7af3zm.com1.z0. ...
- OGNL 对象视图导航语言
[Object Graphics Navigate Language] 类似于EL(Expression Language)表达式, 可以帮助我们在配置文件.JSP中来获取对象的值 这门语言比EL功能 ...
- JavaScript之放大镜效果
在网上也浏览过许多关于JavaScript放大镜效果的文章,有的代码解释得些隐晦难懂,看的我头有点晕晕的╮(╯﹏╰)╭,我的心情是这样的: 吐槽完了,我们动动小鼠标,当鼠标经过下面这张美女图片时就实现 ...
- SQL备份(全)
====================================================================== SQL备份 ======================= ...
- Type 'System.IO.FileStream' with data contract name 'FileStream:http://schemas.datacontract.org/2004/07/System.IO' is not expected.
今天在WCF项目里使用DataContract序列化接口参数的时候,报了这个错,错误详细信息如下: System.ServiceModel.CommunicationException: There ...
- 多个相同script引用探索
1.页面直接就有,或者document.write页面加载同步输出 其实就是当script是页面初始加载的一部分的情况,script是同步的,只有在上一个加载并执行完才会进行下一个script加载. ...
- HTML5标准终于来了,看什么书学习最好??????
最近看了一本书<HTML5网页开发实例详解>,是大众点评的攻城狮写的,觉得很有收获,看样子目前大多数的国内网页都支持HTML5了,全栈工程师是不是必须得会HTML5? 有兴趣的可以讨论呀, ...
- 一个简单的Spring测试的例子
在做测试的时候我们用到Junit Case,当我们的项目中使用了Sring的时候,我们应该怎么使用spring容器去管理我的测试用例呢?现在我们用一个简单的例子来展示这个过程. 1 首先我们新建一个普 ...
- get the runing time of C++ console program.
// 获取程序运行时间.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"#include <time.h>#include < ...
- log4j自动生成日志文件配置
生成文件到默认位置: #生成日志文件 #log4j.appender.systemFile=org.apache.log4j.RollingFileAppender #按天生成 log4j.appen ...