ZOJ 2974 Just Pour the Water
矩阵快速幂。
构造一个矩阵,$a[i][j]$表示一次操作后,$j$会从$i$那里得到水的比例。注意$k=0$的时候,要将$a[i][j]$置为$1$。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} struct Matrix
{
double A[][];
int R, C;
Matrix operator*(Matrix b);
}; Matrix X, Y, Z; int T,n,p; Matrix Matrix::operator*(Matrix b)
{
Matrix c;
memset(c.A, , sizeof(c.A));
int i, j, k;
for (i = ; i <= R; i++)
for (j = ; j <= b.C; j++)
for (k = ; k <= C; k++)
c.A[i][j] = c.A[i][j] + A[i][k] * b.A[k][j];
c.R = R; c.C = b.C;
return c;
} void init()
{
Y.R = n; Y.C = n;
for (int i = ; i <= n; i++) Y.A[i][i] = ;
X.R = n; X.C = n;
Z.R = ; Z.C = n;
} void work()
{
while (p)
{
if (p % == ) Y = Y*X;
p = p >> ;
X = X*X;
}
Z = Z*Y;
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n); memset(X.A, , sizeof X.A);
memset(Y.A, , sizeof Y.A);
memset(Z.A, , sizeof Z.A); for(int i=;i<=n;i++) scanf("%lf",&Z.A[][i]); for(int i=;i<=n;i++)
{
int K; scanf("%d",&K);
for(int j=;j<=K;j++)
{
int id; scanf("%d",&id);
X.A[i][id]=1.0/K;
}
if(K==)
{
X.A[i][i]=1.0;
}
} scanf("%d",&p); init();
work(); for(int i=;i<=n;i++)
{
printf("%.2f",Z.A[][i]);
if(i<n) printf(" "); else printf("\n");
}
}
return ;
}
ZOJ 2974 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. ...
- 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 ...
- ZOJ 2974 矩阵快速幂
题意 给出n个杯子与初始其中有多少水 “同时”进行如下指令 将其中的水同时分入所指定的杯子 进行x次后 输出杯子剩余水量 队友想出应该是一道快速幂 但并不是过去的用初始杯子的水组成的矩阵乘某个矩阵 可 ...
- bnuoj 16493 Just Pour the Water(矩阵快速幂)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=16493 [题解]:矩阵快速幂 [code]: #include <cstdlib> #i ...
- ZOJ 3632 Watermelon Full of Water (线段树 区间更新 + dp)
题目大意: 让每天都能吃到西瓜. 最少须要花多少钱. 思路分析: dp[pos] 就表示 要让 前i天每天都有西瓜吃.最少须要花多少钱. 那么假设你买这个西瓜的话. 那么这个西瓜能吃的持续时间都要更 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- Codeforces Round #311 (Div. 2)B. Pasha and Tea 水题
B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/prob ...
- Codeforces gym 100685 C. Cinderella 水题
C. CinderellaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/C ...
随机推荐
- [Luogu 4092] HEOI/TJOI2016 树
[Luogu 4092] HEOI/TJOI2016 树 搜了树剖标签不知道怎么就跳出了个暴搜题啊! 管他既然做了就发上来吧- 有修改标签就向下搜并修改,遇到标签即停止. 这题是真的真的短. #inc ...
- 解决Sourcetree 每次拉取提交都需要输入密码
问题产生背景 客户端领导决定使用http方式拉取和push代码,所以无法使用之前的ssh方式做免密处理 解决办法 方法1:在.git目录中有个config目录,在路径前配置下用户名和密码即可,如下所示 ...
- 【BZOJ1043】下落的圆盘 [计算几何]
下落的圆盘 Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description 有n个圆盘从天而降,后面落下的可 ...
- 「6月雅礼集训 2017 Day5」吃干饭
[题目大意] 询问[L,R]中选若干个数异或起来得到的答案集合大小.多组数据. 对于50%的数据,$R - L \leq 10^4$ 对于100%的数据,$R - L \leq 10^{18}, T ...
- 阿里云服务器下安装配置 vsftpd —— 基于CentOS 6.3 【简洁版】
原文链接:http://www.tuicool.com/articles/nuiQBja 1.更新yum源 我是直接 yum update 更新的 2.安装vsftp 使用yum命令安装vsftpd ...
- Little Mathematics Knowledge 数学小常识
The sum of arithmetic sequence The sum of geometric sequence A special formula : n·n! = (n+1)! - n! ...
- 2017-3-26 webpack入门(一)
2017-3-26 webpack入门(一) webpack 前端 打包 最近项目里用到了webpack特意总结一下.来源:http://webpackdoc.com 1 概念 1.1 webpack ...
- Spark实现销量统计
package com.mengyao.examples.spark.core; import java.io.Serializable; import org.apache.hadoop.io.Nu ...
- url编码模块
use LWP::SImple; use URI::Escape; encoded_string = uri_escape(raw_string); get(encoded_string);
- Java中基于HotSpot虚拟机的垃圾收集器
名称 过程 优缺点 Serial 进行垃圾收集时,必须暂停其他所有的工作进程,直到它收集结束.是一个单线程收集器. Stop the world. 新生代收集器. 手工设置新生代的大小:-Xmn Ed ...