Problem C: 矩阵对角线求和】的更多相关文章

#include<stdio.h> int main() { ][]; scanf("%d",&n); ,sum2=; ;i<n;i++) ;j<n;j++) scanf("%d",&a[i][j]); ;i<n;i++) { ;j<n;j++) { if(i==j) sum1+=a[i][j]; ) sum2+=a[i][j]; } } printf("%d %d\n",sum1,sum2);…
[Python练习题 028] 求一个3*3矩阵对角线元素之和 ----------------------------------------------------- 这题解倒是解出来了,但总觉得代码太啰嗦.矩阵这东西,应该有个很现成的方法可以直接计算才对-- 啰嗦代码如下: str = input('请输入9个数字,用空格隔开,以形成3*3矩阵:') n = [int(i) for i in str.split(' ')] #获取9个数字 mx = [] #存储矩阵 for i in ra…
题目:求一个3*3矩阵对角线元素之和分析:利用双重for循环控制输入二维数组,再将a[i][i]累加后输出. 例如:下面矩阵的对角线之和为24 1 4 6 2 5 3 9 7 8 public class Prog29 { public static void main(String[] args) { int[][]arr={{1,4,6},{2,5,3},{9,7,8}}; int sum=0; for(int i=0;i<arr.length;i+=2) { for(int j=0;j<…
A Simple Math Problem 一个矩阵快速幂水题,关键在于如何构造矩阵.做过一些很裸的矩阵快速幂,比如斐波那契的变形,这个题就类似那种构造.比赛的时候手残把矩阵相乘的一个j写成了i,调试了好久才发现.改过来1A. 贴个AC的代码: const int N=1e5+10; ll k,m,s[10]; struct mat { ll a[10][10]; }; mat mat_mul(mat A,mat B) { mat res; memset(res.a,0,sizeof(res.a…
二维数组: public static void Main(string[] args) { int[,] a = new int[3, 3]; Random rom = new Random(); for (int x = 0; x < a.GetLength(0); x++) { for (int y = 0; y < a.GetLength(1); y++) { a[x, y] = rom.Next(31); Console.Write("{0} ", a[x, y]…
29 [程序 29 求矩阵对角线之和] 题目:求一个 3*3 矩阵对角线元素之和 程序分析:利用双重 for 循环控制输入二维数组,再将 a[i][i]累加后输出. package cskaoyan; public class cskaoyan29 { @org.junit.Test public void diagonal() { java.util.Scanner in = new java.util.Scanner(System.in); int[][] arr = new int[3][…
要求说明: 题目:求一个3*3矩阵对角线元素之和,矩阵的数据用行的形式输入到计算机中 程序分析:利用双重for循环控制输入二维数组,再将 a[i][i] 累加后输出. 实现思路: [二维数组]相关知识: 定义格式 * a 第一种定义格式: * int[][] arr = new int[3][4];//  arr里面包含3个数组   每个数组里面有四个元素 * 上面的代码相当于定义了一个3*4的二维数组,即二维数组的长度为3,二维数组中的每个元素又是一个长度为4的数组 * b 第二种定义格式 *…
day25 --------------------------------------------------------------- 实例038:矩阵对角线之和 题目 求一个3*3矩阵主对角线元素之和. 分析:不知道3*3矩阵怎么处理,看答案是列表套列表,所以直接上答案吧 1 mat=[[1,2,3,4], 2 [1,2,3,4], 3 [1,2,3,4], 4 [1,2,3,4] 5 ] 6 count = 0 7 for i in range(len(mat)): 8 count +=…
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2441    Accepted Submission(s): 1415 Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) =…
A Short problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1716    Accepted Submission(s): 631 Problem Description According to a research, VIM users tend to have shorter fingers, compared…
Problem Description Lele now is thinking about a simple function f(x). If x < f(x) = x. If x >= f(x) = a0 * f(x-) + a1 * f(x-) + a2 * f(x-) + …… + a9 * f(x-); And ai(<=i<=) can only be or . Now, I will give a0 ~ a9 and two positive integers k…
A Short problem                                                          Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)                                                                                      Total Su…
Problem Description Lele now is thinking about a simple function f(x).If x < 10 f(x) = x.If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 * f(x-10);And ai(0<=i<=9) can only be 0 or 1 .Now, I will give a0 ~ a9 and two positiv…
A Short problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2711    Accepted Submission(s): 951 Problem Description According to a research, VIM users tend to have shorter fingers, compared…
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 155 Accepted Submission(s): 110   Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x.If…
http://acm.hdu.edu.cn/showproblem.php?pid=1757 Problem Description Lele now is thinking about a simple function f(x).If x < 10  f(x) = x.If x >= 10  f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10);And ai(0<=i<=9) can only be…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6621    Accepted Submission(s): 4071 Problem Description Lele now is thin…
Water Problem Time Limit:3000/1000 MS (Java/Others)   Memory Limit:163840/131072 KB (Java/Others)Total Submissions:1228   Accepted:121 [Submit][Status][Discuss] Description 函数 f:Z+→Z .已知 f(1),f(2) 的值,且对于任意 x>1,有 f(x+1)=f(x)+f(x−1)+sin(πx2) . 求 f(n) 的…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1070 题意: 给你a+b和ab的值,给定一个n,让你求a^n + b^n的值(MOD 2^64). 题解: a + b也就是a^1 + b^1,然后要从这儿一直推到a^n + b^n. 矩阵快速幂?o( ̄▽ ̄)d 那么主要解决的就是如何从a^n + b^n推到a^(n+1) + b^(n+1). 下面是推导过程: 由于推a^(n+1) + b^(n+1)要用到a^n + b^n和a^…
Lele now is thinking about a simple function f(x).  If x < 10 f(x) = x.  If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 * f(x-10);  And ai(0<=i<=9) can only be 0 or 1 .  Now, I will give a0 ~ a9 and two positive integers k…
A Short problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2461    Accepted Submission(s): 864 Problem Description According to a research, VIM users tend to have shorter fingers, compared…
Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10); And ai(0<=i<=9) can only be 0 or 1 . Now, I will give a0 ~ a9 and two positive in…
题目:https://www.acwing.com/problem/content/227/ 题意:给你n,k,m,然后输入一个n阶矩阵A,让你求  S=A+A^2+A^3.+......+A^k 思路:首先因为A是矩阵,我们k的范围很大,那么很明显看出A^k可以用矩阵快速幂来计算,但是这样我们只能算出其中一项,还是有k项,那么我们怎么计算和呢 我们可以看出前一项和后一项是有关联的,就是乘了一个A,我们怎么利用前面计算的结果呢,On遍历肯定不行,既然我们用到了遍历,那么优化我们很容易想到二分 假…
对于数列S(n) = a + a^2 + a^3 +....+ a^n; 可以用二分的思想进行下列的优化. if(n & 1) S(n) = a + a^2 + a^3 + ....... + a^n; = a + a^2 + a^3 +..+ a^((n-1) / 2) + a^((n-1) / 2 + 1) + a^((n-1) / 2 + 2) + ... + a^((n-1) / 2 + (n-1) / 2) + a^((n-1) / 2 + (n-1) / 2 + 1); = (1 +…
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2791    Accepted Submission(s): 1659 Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) =…
题目 也是和LightOJ 1096 和LightOJ 1065 差不多的简单题目. #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int num,mod; struct matrix { ][]; }; matrix multiply(matrix x,matrix y)//矩阵乘法 { matrix temp; ;i<num;i++) { ;j<…
题目链接 题意 :给你m和k, 让你求f(k)%m.如果k<10,f(k) = k,否则 f(k) = a0 * f(k-1) + a1 * f(k-2) + a2 * f(k-3) + …… + a9 * f(k-10);思路 :先具体介绍一下矩阵快速幂吧,刚好刚刚整理了网上的资料.可以先了解一下这个是干嘛的,怎么用. 这个怎么弄出来的我就不说了,直接看链接吧,这实在不是我强项,点这儿,这儿也行 //HDU 1757 #include <iostream> #include <s…
题目地址:HDU 1757 最终会构造矩阵了.事实上也不难,仅仅怪自己笨..= =! f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 * f(x-10) 构造的矩阵是:(我代码中构造的矩阵跟这个正好是上下颠倒过来了) |0 1 0 ......... 0|    |f0|   |f1 | |0 0 1 0 ...... 0|    |f1|   |f2 | |...................1| *  |..| = |...…
题意:有一个递推式f(x) 当 x < 10    f(x) = x.当 x >= 10  f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + -- + a9 * f(x-10) 同时ai(0<=i<=9) 不是 0 就是 1: 现在给你 ai 的数字,以及k和mod,请你算出 f(x)%mod 的结果是多少 思路:线性递推关系是组合计数中常用的一种递推关系,如果直接利用递推式,需要很长的时间才能计算得出,时间无法承受,但是现在我们已知…
构造矩阵. 1,当k<=9时,直接输出: 2,当k >9时,先求原矩阵的(k-9)次幂res矩阵,在求幂的过程中对m取余.最后res矩阵再与矩阵F相乘得到矩阵ans,相乘的过程中对m取余.ans矩阵的第一个元素就是答案. PS.orz,这道题一气呵成.只不过我好像和大家构造矩阵的方向有点点差别.这不重要!能做出题就妥! #include<iostream> #include<cstring> #define maxn 12 using namespace std; ]=…