http://www.bnuoj.com/bnuoj/problem_show.php?pid=16493

【题解】:矩阵快速幂

【code】:

  1. #include <cstdlib>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int N;
  8. struct matrix
  9. {
  10. double a[][];
  11. }origin,res;
  12.  
  13. matrix multiply(matrix x,matrix y)
  14. {
  15. matrix temp;
  16. for(int i=;i<=N;i++)
  17. {
  18. for(int j=;j<=N;j++)
  19. {
  20. double ans=;
  21. for(int k=;k<=N;k++)
  22. {
  23. ans+=x.a[i][k]*y.a[k][j];
  24. }
  25. temp.a[i][j]=ans;
  26. }
  27. }
  28.  
  29. return temp;
  30. }
  31.  
  32. matrix calc(int n)
  33. {
  34. while(n)
  35. {
  36. if(n%==)
  37. res=multiply(origin,res);
  38. origin=multiply(origin,origin);
  39. n/=;
  40. }
  41. return res;
  42. }
  43.  
  44. int main()
  45. {
  46. int t;
  47. scanf("%d",&t);
  48. while(t--)
  49. {
  50. int n;
  51. scanf("%d",&n);
  52. N=n;
  53. double x[];
  54. int i,j;
  55. for(i=;i<=n;i++)
  56. {
  57. scanf("%lf",&x[i]);
  58. }
  59. memset(origin.a,,sizeof(origin.a));
  60. for(i=;i<=n;i++)
  61. {
  62. int k;
  63. scanf("%d",&k);
  64. if(k==) origin.a[i][i]=1.0;
  65. for(j=;j<=k;j++)
  66. {
  67. int p;
  68. scanf("%d",&p);
  69. origin.a[p][i]=1.0/k;
  70. }
  71. }
  72. memset(res.a,,sizeof(res.a));
  73. for(i=;i<=n;i++)
  74. {
  75. res.a[i][i]=;
  76. }
  77. int m;
  78. scanf("%d",&m);
  79. calc(m);
  80. for(i=;i<=n;i++)
  81. {
  82. double ans=;
  83. for(j=;j<=n;j++)
  84. {
  85. ans+=res.a[i][j]*x[j];
  86. }
  87. if(i==)
  88. {
  89. printf("%.2lf",ans);
  90. }
  91. else
  92. {
  93. printf(" %.2lf",ans);
  94. }
  95. }
  96. putchar();
  97.  
  98. }
  99. return ;
  100. }

bnuoj 16493 Just Pour the Water(矩阵快速幂)的更多相关文章

  1. zoj 2974 Just Pour the Water矩阵快速幂

    Just Pour the Water Time Limit: 2 Seconds      Memory Limit: 65536 KB Shirly is a very clever girl. ...

  2. 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 ...

  3. zoj 2974 Just Pour the Water (矩阵快速幂,简单)

    题目 对于案例的解释请见下图: 这道要变动提取一下矩阵,之后就简单了 具体解释可看代码: #include <string.h> #include <stdio.h> #inc ...

  4. ZOJ 2794 Just Pour the Water 【矩阵快速幂】

    给你n个杯子,每次有特定的到水规则,倒m次请问最后每个被子里还有多少水 我们很容易发现每次变化的规则相同,那么可以set 一个矩阵存放 然后多次倒水就相当于矩阵相乘,在m 范围达到(1<= M  ...

  5. 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 ...

  6. 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 ...

  7. 焦作网络赛L-Poor God Water【矩阵快速幂】

    God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...

  8. dutacm.club Water Problem(矩阵快速幂)

    Water Problem Time Limit:3000/1000 MS (Java/Others)   Memory Limit:163840/131072 KB (Java/Others)Tot ...

  9. ACM-ICPC 2018 焦作赛区网络预赛 L Poor God Water(矩阵快速幂,BM)

    https://nanti.jisuanke.com/t/31721 题意 有肉,鱼,巧克力三种食物,有几种禁忌,对于连续的三个食物:1.这三个食物不能都相同:2.若三种食物都有的情况,巧克力不能在中 ...

随机推荐

  1. 304 CORS

    304响应, CORS问题: 没有 Access-Control-Allow-Origin 这个头信息时,以前次返回的200请求为准. 示例:可能已被删除 http://7af3zm.com1.z0. ...

  2. OGNL 对象视图导航语言

    [Object Graphics Navigate Language] 类似于EL(Expression Language)表达式, 可以帮助我们在配置文件.JSP中来获取对象的值 这门语言比EL功能 ...

  3. JavaScript之放大镜效果

    在网上也浏览过许多关于JavaScript放大镜效果的文章,有的代码解释得些隐晦难懂,看的我头有点晕晕的╮(╯﹏╰)╭,我的心情是这样的: 吐槽完了,我们动动小鼠标,当鼠标经过下面这张美女图片时就实现 ...

  4. SQL备份(全)

    ====================================================================== SQL备份 ======================= ...

  5. 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 ...

  6. 多个相同script引用探索

    1.页面直接就有,或者document.write页面加载同步输出 其实就是当script是页面初始加载的一部分的情况,script是同步的,只有在上一个加载并执行完才会进行下一个script加载. ...

  7. HTML5标准终于来了,看什么书学习最好??????

    最近看了一本书<HTML5网页开发实例详解>,是大众点评的攻城狮写的,觉得很有收获,看样子目前大多数的国内网页都支持HTML5了,全栈工程师是不是必须得会HTML5? 有兴趣的可以讨论呀, ...

  8. 一个简单的Spring测试的例子

    在做测试的时候我们用到Junit Case,当我们的项目中使用了Sring的时候,我们应该怎么使用spring容器去管理我的测试用例呢?现在我们用一个简单的例子来展示这个过程. 1 首先我们新建一个普 ...

  9. get the runing time of C++ console program.

    // 获取程序运行时间.cpp : 定义控制台应用程序的入口点.// #include "stdafx.h"#include <time.h>#include < ...

  10. log4j自动生成日志文件配置

    生成文件到默认位置: #生成日志文件 #log4j.appender.systemFile=org.apache.log4j.RollingFileAppender #按天生成 log4j.appen ...