TOJ 3929 A3
来源:互联网 发布:php判断奇数偶数 编辑:程序博客网 时间:2024/05/17 02:14
A3
描述
The island of the Azeroth is so big that people must use the gryphon (one kind of animal like lion and eagle) to go over the island. One day, a paladin has finished a long trip in the Azeroth. He has made a matrix of A. If the city i and city j have a directly gryhon flying road, Ai,j=1, otherwise Ai,j=0.
Then the paladin is good at mathematics, so he immediately calculated A·A(A2), A·A·A(A3),…,A·A·…·A(An). (C=A·B iff Ci,j=∑Ai,k·Bk,j).
Another day, one priest asked the paladin to give the number of triangles (The citys i, j, k form a triangle if Ai,j=Aj,k=Ak,i=1) which all the gryphon flying roads form. But the paladin only sends a letter of only a matrix of A3.
Can you help the priest to calculate the number of triangles?
输入
It has multiple test cases in this problem. In each case, first is the number of city n (1<=n<=1000). And then the matrix of A3.
The input is terminated by n=0.
输出
You must print the number of triangles. One case per line.
样例输入
32 3 33 2 33 3 20
样例输出
1
1个0 1 的矩阵 A
a[i][j] = 1 表示i 到 j可达 或者说 i 到 j 有1条路
例如 A:
0 1 1
1 0 1
1 1 0
而A2 = A* A
a[i][j] 的含义是
从 i 到j走 i 步的路的总数
A的i次方 代表 A[i,j] i到j走i步的路的总数
A^3矩阵里 A[i,i] 就是表示走三步 能回来的路径种类
以上是学长给我普及的知识 膜拜
#include <stdio.h>int main(){int n,i,j,count,a;while(scanf("%d",&n),n){count = 0;for(i = 1;i <= n; i++){for(j = 1; j <= n; j++){scanf("%d",&a);if(i == j)count += a; }}printf("%d\n",count/6);}return 0;}
- TOJ 3929 A3
- a3
- a3
- a3
- A3: pythagorean
- a3~a6
- Cindy 3.0a3 released
- A3.1节
- A3/A8/A5算法
- TOJ 2976
- toj 3140
- toj 1153
- TOJ 1772
- TOJ 3250
- TOJ 3051
- TOJ 4303
- TOJ 1005
- TOJ 1545
- Poj 1222 EXTENDED LIGHTS OUT (高斯消元解异或方程组 开关问题)
- ffmpeg分析 之 如何解析mpegts流
- 注解
- android之Animations(动画)
- 2-D DFT and DCT using MATLAB
- TOJ 3929 A3
- 最小值最大化
- 图形学个人站点收集
- ACboy needs your help again!(栈与队列)
- web页面表单显示代码类名称的方法介绍
- 帝国CMS留言板增加字段功能
- 为什么说支付宝推出余额宝值得赞赏?
- Tomcat及MySQL中文乱码问题解决方案总览
- 黑马程序员_银行服务系统