bzoj 1712: [Usaco2007 China]Summing Sums 加密
1712: [Usaco2007 China]Summing Sums 加密
Description
.jpg)
Input
Output
Sample Input
1
0
4
INPUT DETAILS:
Three cows, with starting numbers 1, 0, and 4; four repetitions of the
encryption algorithm.
Sample Output
25
29
OUTPUT DETAILS:
The following is a table of the cows' numbers for each turn:
Cows' numbers
Turn Cow1 Cow2 Cow3
0 1 0 4
1 4 5 1
2 6 5 9
3 14 15 11
4 26 25 29
#include<stdio.h>
#include<iostream>
using namespace std;
#define ll long long
const int M=;
const int N=;
int m,n,s,i,A[N];
ll a[][],c[][],ans[][];
void mul(ll a[][],ll b[][],ll ans[][])
{
int i,j,k;
for(i=;i<=;i++)
for(j=;j<=;j++)
{
c[i][j]=;
for(k=;k<=;k++)
c[i][j]=(c[i][j]+a[i][k]*b[k][j]%M+M)%M;
}
for(i=;i<=;i++)
for(j=;j<=;j++)
ans[i][j]=c[i][j];
}
int main()
{
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
scanf("%d",&A[i]),s=(s+A[i])%M;
ans[][]=ans[][]=;
a[][]=-;a[][]=;a[][]=n-;
while(m)
{
if(m&) mul(ans,a,ans);
mul(a,a,a);
m>>=;
}
int t=ans[][]*s%M;
for(i=;i<=n;i++)
printf("%d\n",(ans[][]*A[i]%M+t+M)%M);
return ;
}
bzoj 1712: [Usaco2007 China]Summing Sums 加密的更多相关文章
- 1712: [Usaco2007 China]Summing Sums 加密
		
1712: [Usaco2007 China]Summing Sums 加密 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 338 Solved: 12 ...
 - BZOJ_1712_[Usaco2007 China]Summing Sums 加密_矩阵乘法
		
BZOJ_1712_[Usaco2007 China]Summing Sums 加密_矩阵乘法 Description 那N只可爱的奶牛刚刚学习了有关密码的许多算法,终于,她们创造出了属于奶牛 ...
 - BZOJ1712 : [Usaco2007 China]Summing Sums 加密
		
设$s[i]$为进行$i$次加密后所有奶牛数字的和,有$s[i]=(n-1)s[i-1]$. 设$c[i]$为某头固定的奶牛进行$i$次加密后的数字, 若$i$为奇数,有: \[c[i]=((1-n) ...
 - 【bzoj1712】[Usaco2007 China]Summing Sums 加密  矩阵乘法
		
题目描述 那N只可爱的奶牛刚刚学习了有关密码的许多算法,终于,她们创造出了属于奶牛的加密方法.由于她们并不是经验十足,她们的加密方法非常简单:第i只奶牛掌握着密码的第i个数字,起始的时候是Ci(0≤C ...
 - 【BZOJ1713】[Usaco2007 China]The Bovine Accordion and Banjo Orchestra 音乐会 斜率优化
		
[BZOJ1713][Usaco2007 China]The Bovine Accordion and Banjo Orchestra 音乐会 Description Input 第1行输入N,之后N ...
 - BZOJ_1713_[Usaco2007 China]The Bovine Accordion and Banjo Orchestra 音乐会_斜率优化
		
BZOJ_1713_[Usaco2007 China]The Bovine Accordion and Banjo Orchestra 音乐会_斜率优化 Description Input 第1行输入 ...
 - BZOJ 1692: [Usaco2007 Dec]队列变换( 贪心 )
		
数据 n <= 30000 , 然后 O( n² ) 的贪心也过了..... USACO 数据是有多弱啊 = = ( ps : BZOJ 1640 和此题一模一样 , 双倍经验 ) ------ ...
 - BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
		
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
 - BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
		
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
 
随机推荐
- javascript 变量类型判断
			
一.typeof 操作符 对于Function, String, Number ,Undefined 等几种类型的对象来说,他完全可以胜任,但是为Array时 "); typeof arr ...
 - VMware12序列号
			
VMware tools怎么删除 rpm -e open-vm-tools-desktop vm12序列号 5A02H-AU243-TZJ49-GTC7K-3C61NVF5XA-FNDDJ-085GZ ...
 - linux 3389连接工具Rdesktop
			
简单使用 工作机换成战斗机了,改用ubuntu,原来的windows7上东西笔记多,还不想重装.用rdesktop来远程连接windows: sudo apt-get install rdesktop ...
 - Linux信号函数
			
1. signal函数: #include <signal.h> void (*signal(int signo, void (*func)(int)))(int); ret-成功返回信号 ...
 - centos 挂在ntfs
			
Installing build-essentials in CentOS (make, gcc, gdb):http://www.techblogistech.com/2012/03/install ...
 - mybatis 联结查询
			
一.查询 员工(tbl_employee)时,关联 查询出 员工对于的部门信息 (tab1_dept),一对一查询,或者多对一查询 适用 emp bean里面 包含 部门bean dept属性对象 1 ...
 - linux命令(16):mv命令
			
移动文件:mv /mnt/test.log /home 移动目录:mv -f /mnt/test /home [带-f参数如目的已存在同名文件,则直接覆盖掉] 文件改名:mv /mnt/test /m ...
 - Codeforces 707C Pythagorean Triples(构造三条边都为整数的直角三角形)
			
题目链接:http://codeforces.com/contest/707/problem/C 题目大意:给你一条边,问你能否构造一个包含这条边的直角三角形且该直角三角形三条边都为整数,能则输出另外 ...
 - Matlab处理数据导出Paraview可读的vtk文件(二)
			
由于我在用SPH方法仿真时用的是FORTRAN语言,并且没有找到直接输出vtk文件的代码,因此偷懒通过MATLAB转换一下数据. 用到的Matlab子程序可通过一下链接找到. Matlab处理数据导出 ...
 - 【转】kubernetes 中 deployment 支持哪些键值
			
这个比较全,可以参考 ================= https://www.addops.cn/post/kubernetes-deployment-fileds.html ========== ...