Just Pour the Water ZOJ - 2974 (矩阵快速幂)

深入解析TMC2209 UART寄存器配置:从基础指令到高级参数调优 本文深入解析TMC2209 UART寄存器配置,从基础指令到高级参数调优,涵盖电流控制、微步细分等关键设置。通过实战案例和优化技巧,帮助开发者高效配置步进电机驱动,提升系统性能和稳定性。特别介绍了UART通信协议和CRC校验实现,确保数据传输可靠性。 阅读详情

Just Pour the Water

ZOJ - 2974

Shirly is a very clever girl. Now she has two containers (A and B), each with some water. Every minute, she pours half of the water in A into B, and simultaneous pours half of the water in B into A. As the pouring continues, she finds it is very easy to calculate the amount of water in A and B at any time. It is really an easy job :).

But now Shirly wants to know how to calculate the amount of water in each container if there are more than two containers. Then the problem becomes challenging.

Now Shirly has N (2 <= N <= 20) containers (numbered from 1 to N). Every minute, each container is supposed to pour water into another K containers (K may vary for different containers). Then the water will be evenly divided into K portions and accordingly poured into anther K containers. Now the question is: how much water exists in each container at some specified time?

For example, container 1 is specified to pour its water into container 1, 2, 3. Then in every minute, container 1 will pour its 1/3 of its water into container 1, 2, 3 separately (actually, 1/3 is poured back to itself, this is allowed by the rule of the game).


Input

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 10) which is the number of test cases. And it will be followed by T consecutive test cases.

Each test case starts with a line containing an integer N, the number of containers. The second line contains N floating numbers, denoting the initial water in each container. The following N lines describe the relations that one container(from 1 to N) will pour water into the others. Each line starts with an integer K (0 <= K <= N) followed by K integers. Each integer ([1, N]) represents a container that should pour water into by the current container. The last line is an integer M (1<= M <= 1,000,000,000) denoting the pouring will continue for M minutes.

Output

For each test case, output contains N floating numbers to two decimal places, the amount of water remaining in each container after the pouring in one line separated by one space. There is no space at the end of the line.

Sample Input
1
2
100.00 100.00
1 2
2 1 2
2

Sample Output
75.00 125.00

Note: the capacity of the container is not limited and all the pouring at every minute is processed at the same time.

题意 给出n个杯子与初始水量同时进行操作 将其中的水同时平均分入所指定的杯子 进行x次后 输出杯子剩余水量

刚拿到这个题,第一反应是递推找规律,但是因为每个杯子的初始水量是未知的,所以能找的只是每个杯子水量与其余杯子水量的关系。

但是看到了操作次数巨大,而且最多只有20个杯子,感觉可以用快速幂去做。

我们假设矩阵a[i][j]代表第i个杯子的水有a[i][j]来自第j个杯子,这样用init矩阵表示初始水量,unit矩阵表示每次操作后的变化,最后init*pow(unit,k)即为所求。

注意当某一个杯子不用向其他杯子操作时,要将相应位置填为1

例如所给样例

这里写图片描述

A : ( 1/2 + 1/4 ) * 100 = 75
B: (1/2 + 3/4 ) * 100 = 125


code:

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <vector>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    #define LL long long
    const double eps=1e-14;
    int n;
    struct matrix{
        double f[22][22];//矩阵每列代表每个杯子,每行代表水的来自每个杯子
    }c;
    void mul(matrix &a,matrix b)//矩阵乘法
    {
        int i,j,k;
        memset(c.f,0,sizeof(c.f));
        for(k=0;k<n;k++)
        {
            for(i=0;i<n;i++)
            {
                if(a.f[i][k]<eps)continue;
                for(j=0;j<n;j++)
                {
                    if(b.f[k][j]<eps)continue;
                    c.f[i][j]+=a.f[i][k]*b.f[k][j];
                }
            }
        }
        a=c;
    }
    matrix pow_mod(matrix a,int b)//矩阵快速幂
    {
        matrix s;
        memset(s.f,0,sizeof(s.f));
        for(int i=0;i<n;i++)
            s.f[i][i]=1;
        while(b)
        {
            if(b&1)
                mul(s,a);
            mul(a,a);
            b=b>>1;
        }
        return s;
    }
    int main()
    {
        int m,T;
        cin>>T;
        while(T--)
        {
            cin>>n;
            double a[22],p,s;
            int i,j,k,x,y;
            for(i=0;i<n;i++)
                cin>>a[i];
            matrix e;
            memset(e.f,0,sizeof(e.f));
            for(i=0;i<n;i++)
            {
                cin>>k;
                if(k==0)    // 如果是0,这个杯子里的水不会倒给别的杯子它自己始终是1
                    e.f[i][i]=1;
                for(j=0;j<k;j++)
                {
                    cin>>x;
                    e.f[i][x-1]=1.0/k;//否则记录给他杯子倒水的比例
                }
            }
            cin>>m;
            e=pow_mod(e,m);//求得最终每个杯子来自其他杯子的比例
            double ans[22];
            for(i=0;i<n;i++)
            {
                ans[i]=0;
                for(j=0;j<n;j++)
                ans[i]+=a[j]*e.f[j][i];//用原来每个杯子的水量乘比例求和即最终每个杯子水量
            }
            printf("%.2f",ans[0]);
            for(i=1;i<n;i++)
                printf(" %.2f",ans[i]);
            printf("\n");
        }
        return 0;
    }
    /*
        矩阵:
        f[i][j]表示i倒水到j里的概率
    */


手机端实时检测:YOLOv8n轻量化改进,骁龙865上35FPS,mAP+3.2% YOLOv8n-Lite的改进不是简单的“砍通道、降分辨率”,而是结合手机端硬件特性(NPU加速、内存限制)和场景需求(小目标检测),通过“卷积拆分减少计算、通道瘦身适配内存、特征强化保留精度”的协同策略,在骁龙865上实现35FPS实时性与mAP+3.2%的双赢。该方案已在手机端AR应用中落地,支持实时手势识别、物体测量等功能,功耗比原始模型降低40%(连续检测1小时仅耗电12%)。 阅读详情

相关推荐

il2cpp分析-gobal-metadata.dat解密

打开ida,把libil2cpp拖到ida中按快捷键Shift+F12等待字符串分析完后,搜索global-metadata.dat。ida中双击sub_57EE7C进入,VS code中也跳转到LoadMetadataFile函数。VSCode打开il2cpp源代码,全局搜索global-metadata.dat。工具:010Editor,IDA 7.5,Jadx,VS Code。判断加密逻辑为根据文件的长度循环读取字节码做亦或加密。双击搜索出来的结果,切记要选il2cpp目录下的。

Android_machong的博客 8024

ZOJ 2974 Just Pour the Water【5th浙江省赛】【矩阵乘法】

ZOJ-2974-Just Pour the Water

Linoy 1000

STK传感器配置全攻略:从光学到雷达的7种视场类型详解(附避坑指南)

本文详细解析了STK软件中传感器的7种视场类型,从基础的Simple Conic、Complex Conic到高级的SAR与EOIR,提供了完整的配置步骤与实战避坑指南。重点阐述了雷达、光学等不同物理设备的建模选择逻辑,并针对常见的“No Access”等报错问题给出了系统性的排查方案,帮助工程师高效完成卫星系统设计与任务分析。

weixin_29232507的博客 228

ZOJ 1973 Just Pour the Water(矩阵快速幂)

ZOJ 1973 Just Pour the Water(矩阵快速幂)

1737

Java 简易版 UDP 多人聊天室

【代码】Java 简易版 UDP 多人聊天室。

nmy15570188135的博客 1187

用Multisim和AD2复刻经典:手把手教你搭建μA741三角波-方波发生器(附完整避坑指南)

本文详细介绍了如何使用Multisim和AD2搭建基于μA741运算放大器的三角波-方波发生器,包括电路原理、Multisim仿真流程、AD2硬件搭建及调试技巧。通过对比理论计算、仿真和实测数据,深入分析器件非理想特性的影响,并提供16个典型问题的解决方案,帮助读者掌握波形发生器的设计原理和工程调试经验。

weixin_28744423的博客 284

Just Pour the Water(矩阵快速幂)

Just Pour the Water Time Limit: 2 Seconds      Memory Limit: 65536 KB Shirly is a very clever girl. Now she has two containers (A and B), each with some water. Every minute, she pours half of the ...

Simone chou... 336

手把手完整实现STM32+NB-IoT+MQTT+ThingsCloud云平台+手机APP(Android或iOS)及微信小程序及Web app 应用

本教程以远程温湿度显示及点灯作为示例。最终效果实现本地OLED显示屏、云平台和手机APP、微信小程序和Web App可远程查看温湿度数据,并可远程控制LED灯亮灭。以此完成基于MQTT协议的NB-IoT远程发布订阅数据,以此在本教程基础上可扩展开发更多的功能。

嵌入式阿齐Archie 2万+

ZOJ 2974 Just Pour the Water(矩阵快速幂)

经典的倒水问题! ZOJ 2974 Just Pour the Water(矩阵快速幂) Description Shirly is a very clever girl. Now she has two containers (A and B), each with some water. Every minute, she pours half of the water in A into B, and simultaneous pours h

1564

Python 爬虫实战:社交媒体(Facebook)评论数据抓取与情感分析

在当今数字化时代,社交媒体平台如 Facebook 已成为人们日常生活中不可或缺的一部分。它不仅是人们分享生活点滴、交流思想的场所,也为企业和研究人员提供了丰富的数据资源。通过分析社交媒体上的评论数据,我们可以了解用户的情感倾向、产品反馈以及社会热点话题等。本文将详细介绍如何使用 Python 爬虫技术抓取 Facebook 上的评论数据,并进行情感分析。这不仅是一次技术实战,更是一次数据探索之旅。

yansideyucsdn的博客 671

U盘插入电脑时发出声音但不显示——编程解决方案

以上是一些常见的编程解决方案,帮助您解决U盘插入电脑时发出声音但不显示的问题。请注意,这些解决方案可能因不同的情况而略有不同,因此请根据您的具体情况进行调整和尝试。当您将U盘插入电脑时,如果您听到了连接声音,但是U盘却没有在文件资源管理器或桌面上显示出来,这可能是由于一些常见问题导致的。U盘的文件系统格式可能与您的计算机不兼容,导致无法正确识别。如果输出显示U盘的文件系统格式与您的计算机不兼容,您可以尝试重新格式化U盘或使用其他兼容的文件系统格式。其中,X是U盘的磁盘编号,Y是您想要分配给U盘的盘符。

ByteEchoX的博客 2461

【矩阵快速幂】ZOJ 2974 Just Pour the Water

Source : ZOJ 2974 Just Pour the Water http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1973 Problem Description Shirly is a very clever girl. Now she has two containers (A and B), each wit

Hacker_vision 544

【AI产品思路】用户旅程图与用户全生命周期:到底是什么关系?

用户旅程图(User Journey Map)和用户全生命周期(User Lifecycle)是两种不同的分析框架。用户旅程聚焦单次交易体验的完整过程(如浏览→下单→售后),关注触点、情绪和优化点;而用户生命周期则关注用户与平台的长期关系(从认知到流失),着重提升留存和LTV。两者互为补充:生命周期是时间维度的关系框架,旅程图是行为维度的体验路径。电商运营中,旅程优化改善单次体验,生命周期优化解决长期增长问题,二者结合才能实现体验提升与商业效率的双赢。

qq_25438419的博客 217

【ZOJ 2974】Just Pour the Water(矩阵快速幂)

传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2974 题意 给出n个杯子与初始水量同时进行操作 将其中的水同时平均分入所指定的杯子 进行x次后 输出杯子剩余水量 刚拿到这个题,第一反应是递推找规律,但是因为每个杯子的初始水量是未知的,所以能找的只是每个杯子水量与其余杯子水量的关系。 但是看到...

a5615024的博客 193

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Just Pour the Water ZOJ - 2974 矩阵快速幂

思路:用一个N*N的矩阵的第一行来记录水量。另外一个矩阵记录转移的方式,不是很好描述,具体看代码。当k是0的时候,水量都给了自己。#include &lt;iostream&gt; #include &lt;cstdio&gt; #include &lt;cstring&gt; using namespace std; int n; const int N = 25; struct Matrix ...

Peppermint__的博客 373

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

zoj 2974 Just Pour the Water矩阵快速幂

Just Pour the WaterTime Limit: 2 Seconds Memory Limit: 65536 KB Shirly is a very clever girl. Now she has two containers (A and B), each with some water. Every minute, she pours half of the wa...

weixin_30814329的博客 116

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

ZOJ 2974-Just Pour the Water(矩阵快速幂)

Description Shirly is a very clever girl. Now she has two containers (A and B), each with some water. Every minute, she pours half of the water in A into B, and simultaneous pours half of the water

Halo 921

ZOJ - 2974 Just Pour the Water(矩阵快速幂)

矩阵快速幂的题,之前没怎么写过,参考的别人的代码。#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;cstdio&gt; using namespace std; typedef vector&lt;double&gt; vec; typedef vector&lt;vec&gt; mat; typedef long l...

GYH0730的博客 304

Just Pour the Water ZOJ - 2974 (矩阵快速幂)

题目具体转载来自大佬:https://blog.youkuaiyun.com/Anxdada/article/details/73603752我觉得他风格很好这叫C++写题哈哈代码:#include&lt;bits/stdc++.h&gt; using namespace std; double s[25],result[25]; int size; struct Ma { double a[25][...

galesaur_wcy 283

ZOJ 2974 Just Pour the Water(矩阵快速幂)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2974给出一个水桶,里面有不同的谁,每分钟根据给出的要求平分水桶里的水。 使用矩阵乘法,要注意当输入为0时水留在原来的桶里#include<iostream> #include<cstdio> #include<set> #include<string> #incl

宝树啊宝树 564

ZOJ2974 Just Pour the Water(5th 浙江省赛)矩阵快速幂

问题链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2974问题描述:Just Pour the WaterTime Limit: 2 Seconds      Memory Limit: 65536 KBShirly is a very clever girl. Now she has two containers ...

Jasonare的博客 259

ZOJ 2974 Just Pour the Water

Just Pour the Water Time Limit:2 Seconds Memory Limit:65536 KB Shirly is a very clever girl. Now she has two containers (A and B), each with some water. Every minute, she pours half of the wa...

~ 565

zoj 2974 Just Pour the Water 矩阵

#include #include #include #include #include #include using namespace std; #define LL long long const double eps=1e-14; int n; struct matrix{ double f[22][22]; }c; void mul(matrix &a,matrix

冷月之殇 1301

ZOJ - 2974 Just Pour the Water

<br />表示十分无语,本想写个矩阵类的。同时重载它的乘法运算之类的。但总是异常退出,把类里的矩阵开小了后就没问题了。不知道为什么!! 我只开了double[22][22]大小的数组啊 T_T<br /> <br />最后还是算了, 直接写吧。 只是代码可重用性不怎么好。<br /> <br /> <br />这里在说下这个矩阵的构造:c[i][j] 表示i杯子向j杯子倒入自己原先c[i][j]分之一的水。<br /> <br /> <br />#include <cstdio> #include <a

李へいてい 1351

zoj 2974 Just Pour the Water

思路:由于M相当之大,因此可以构造矩阵快速幂来求解 mat[i][j]表示第i个被子给第j个被子的水的百分比,如果k==0,则全给自己,mat[i][i]=1.0; 代码如下: #include #include #include #include #include #include #include #include #define MAX 31 using namespa

yueqiq 578
上一篇: Hurdles of 110m ZOJ - 2972 (DP)
下一篇: Proper Nutrition (暴力+思维)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值