A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© leo_yang 中级黑马   /  2016-5-1 23:45  /  983 人查看  /  8 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import java.util.Scanner;


public class Main {


/**
* @param args
*/
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int i = 0, j = 0, k = 0,l = 0;
while (read.hasNext()) {
int s=0;
int n = read.nextInt();
if(n==0){
return;
}
int a[][]=new int[n][n];
int b[][]=new int[n][n];
int c[][]=new int[n][n];
for(i = 0;i<n;i++){
for(j = 0;j<n;j++){
a[i][j]=read.nextInt();
}
}
int m = read.nextInt();
for(l=0;l<m;l++){
int x = read.nextInt();
System.out.println(String.format("关系R的%d次幂:",x));
Relation rel = new Relation(a,n);
for(i=0;i<x-1;i++){
rel.poap(a,x);
}
Set set = new Set(rel,n);
set.serprint();
}

}
}
}
class Relation{
int data[][];
int n;
public Relation(int data[][],int n){
this.data=data;
this.n=n;
}
public void poap(int a[][],int x){
int i = 0,j = 0,k = 0;
int s = 0;
int c[][]=new int[n][n];
for(i = 0;i<n;i++){
for(j = 0;j<n;j++){
s=0;
for(k = 0;k<n;k++){
s+=a[i][k]*data[k][j];
}
c[i][j]=s;
}
}
for(i = 0;i<n;i++){
for(j = 0;j<n;j++){
data[i][j]=c[i][j];
}
}
if(x==0){
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(i==j){
data[i][j]=1;
}
else{
data[i][j]=0;
}
}
}
}
}
}
class Set{
Relation a;
int n;
public Set(Relation a,int n){
this.a=a;
this.n=n;
}
public void serprint(){
int i = 0,j=0;



for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (a.data[i][j] > 1) {
a.data[i][j] = 1;
}
System.out.print(a.data[i][j]);
if (j != n - 1) {
System.out.print(" ");
}
}
System.out.println();
}
}
}

8 个回复

倒序浏览
特点就是没有名字,这特点够独特吧?
回复 使用道具 举报
写的有点乱,看的头晕
回复 使用道具 举报
建议截图,虽然这样可以方便复制,但是一般人都懒得去新建demo
回复 使用道具 举报
怎么了  为什么要看?
你抛个异常出来啊
回复 使用道具 举报
你要问的是啥?
回复 使用道具 举报
Erry 中级黑马 2016-5-2 11:16:50
7#
没懂,大婶的世界,小菜鸟安静的飞过。
回复 使用道具 举报
格式太乱了,感觉像是直接复制的,一堆括弧,lz还是整理下,用代码的方式粘贴吧
回复 使用道具 举报
要不我给你讲个故事吧!!!从前啊!有个程序员辞职不干了,然后有一个新的程序员接替他的工作,当新来的程序员看见辞职的程序员写的代码的时候...悲剧发生了...新来的程序员把辞职的程序员用刀捅死在家中........
知道我想告诉什么吗?......
能不能把你问的问题明确出来...还有.你敢不敢有几个注释{:2_38:}???....!!!!!!!!!!!!!!!!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马