POJ 3735 Training little cats

题目链接: http://poj.org/problem?id=3735

一开始的想法是建立两个(n+1)*(n+1)的矩阵A,对角线均为1,其他元素初始为0,另一个(n+1)*1的矩阵B,对于元素(b i1) ∈ B,1<= i <=n(矩阵元素坐标在讨论中均以1开始),表示第n只猫的花生个数,初始均为0,b(n+1)1=1。

对于g i 操作,将(a i(n+1)) 加1。((aij) ∈ A)

对于e i 操作,将第 i 行全置为零。

对于s i j 操作,将第 i 行和第 j 行交换。

这样,修改后的矩阵A对其求m次幂,再与矩阵B相乘得到一个(n+1)*1的矩阵,第 i 行(1<= i <=n)表示第n只猫最后的花生个数。

对于题目样列,算式如下,

仔细思考,上述矩阵可以简化,重新定义(n+1)*(n+1)的矩阵A,对角线均为1,对于(a i1) ∈ A,1<= i <=n表示第n只猫的花生个数,初始均为0。

对于g i 操作,将(a i 1) 加1。

对于e i 操作,将第 i 行全置为零。

对于s i j 操作,将第 i 行和第 j 行交换。

这个方法与前面的是等价的,对A求m次幂,(a i1) ∈ Am,1<= i <=n表示第n只猫的花生个数。

时间: 2024-10-10 20:11:50

POJ 3735 Training little cats的相关文章

poj 3735 Training little cats 矩阵

假设n=3 构造矩阵[1,0,0,0] 对于g 1操作,构造矩阵(0行i列++) 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 1 对于e 1操作,构造矩阵 (i整列清空) 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 对于s 1 2操作,构造矩阵 (i,j整列交换) 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 将k次操作依次按上述构造矩阵,得到一个轮回的转置矩阵.做m次快速幂就行了. 最坑的地方在于,答案要用longlong存,而longlo

矩阵快速幂 POJ 3735 Training little cats

题目传送门 1 /* 2 题意:k次操作,g:i猫+1, e:i猫eat,s:swap 3 矩阵快速幂:写个转置矩阵,将k次操作写在第0行,定义A = {1,0, 0, 0...}除了第一个外其他是猫的初始值 4 自己讲太麻烦了,网上有人讲的很清楚,膜拜之 5 详细解释:http://www.cppblog.com/y346491470/articles/157284.html 6 */ 7 #include <cstdio> 8 #include <cstring> 9 #inc

poj 3735 Training little cats(构造矩阵)

http://poj.org/problem?id=3735 大致题意: 有n只猫,开始时每只猫有花生0颗,现有一组操作,由下面三个中的k个操作组成: 1. g i 给i只猫一颗花生米 2. e i 让第i只猫吃掉它拥有的所有花生米 3. s i j 将猫i与猫j的拥有的花生米交换 现将上述一组操作循环m次后,问每只猫有多少颗花生? 再一次感受到了矩阵的强大...循环m次,且m这么大,很容易想到构造转换矩阵,但如何构造是个问题.尤其是第一种操作,第i只猫增加一个花生.具体构造方法是把矩阵扩大为(

POJ 3735 Training little cats 矩阵快速幂应用

点击打开链接 Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9807   Accepted: 2344 Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to

poj 3735 Training little cats(矩阵快速幂)

Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make the cats to do some exercises. Facer has well designed a set of moves for his cats. He is now asking you t

[POJ 3735] Training little cats (构造矩阵、矩阵快速幂)

Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9613   Accepted: 2296 Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make th

POJ 3735 Training little cats (矩阵快速幂)

Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10593   Accepted: 2532 Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make t

poj 3735 Training little cats矩阵快速幂

Training little cats Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make the cats to do some exercises. Facer has well designed a set of moves for his cats. H

poj 3735 Training little cats(矩阵构造,快速幂)

Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10350   Accepted: 2471 Description Facer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make t

poj 3735 Training little cats (矩阵快速幂)

题目链接: http://poj.org/problem?id=3735 题意: 有n只猫咪,开始时每只猫咪有花生0颗,现有一组操作,由下面三个中的k个操作组成:               1. g i 给i只猫咪一颗花生米               2. e i 让第i只猫咪吃掉它拥有的所有花生米               3. s i j 将猫咪i与猫咪j的拥有的花生米交换 现将上述一组操作做m次后,问每只猫咪有多少颗花生? 思路: http://www.cnblogs.com/acS