标题:[求助]看一看这道英文题!要怎样做!
只看楼主
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
 问题点数:0 回复次数:6 
[求助]看一看这道英文题!要怎样做!

Multiplying Matrices
Write a program to compute the product of two matrices A and B that are multipliable in the form of AB.

Input
The first line of input is the number of all the test cases that follow. For each test case, there are three positive integer m, n, p (m, n, p <= 100) on the first line, meaning that A's dimension is m rows by n columns while B's is n rows by p columns. Then comes the data of matrices A and B. Matrix A is represented by m lines of integers ranging in [-1000, 1000], with each line containing n integers separated by a space. A line is corresponding to a row of a matrix. The data format for matrix B is much the same except for its potentially different dimensions. Please refer to the section Sample Input.

Output
For each test case, print the product of A multiplied by B in the form described in the section Input, but do not include any dimension description.

Sample Input
2
2 2 2
1 2
3 4
1 2
3 4
1 2 1
1 0
0
1

Sample Output
7 10
15 22
0
使用动态内存分配(malloc()和free())完成。

[此贴子已经被作者于2006-12-3 15:34:20编辑过]

搜索更多相关主题的帖子: 英文 Matrix test line form 
2006-12-03 15:33
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
得分:0 

先写了一点!除了红色字体的部分!大家看看这样行不行!
#include <stdio.h>
#include <stdlib.h>
#define M 100
#define N 100

struct student
{
int r[M][N];
}name;

int main(void)
{
int i, j, m, n, p, s ,k = 0, sum = 0;
struct student *p1;
struct student *p2;

scanf("%d%d%d%d", &m, &n, &p, &s);
for(i = 1;i <= m;i ++)
{
p1 = (struct student*)malloc(sizeof(struct student));
p2 = (struct student*)malloc(sizeof(struct student));
for(i = 0;i < n;i ++)
for(j = 0;j < p;j ++)
{
scanf("%d", &p1->r[i][j]);
}
for(i = 0;i < p;i ++)
for(j = 0;j < s;j ++)
{
scanf("%d", &p2->r[i][j]);
}
for(i = 0;i < n;i ++)
{
for(j = 0;j < p;j ++)
{
sum += p1->r[i][j]*p2->r[j][k];
k ++;
printf("%d",sum);
}
sum = 0;
}
free(p1);
free(p2);


}

return 0;
}


该学习了。。。
2006-12-03 17:14
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
得分:0 

大家帮着看看这个程序错在了那里!这里有很多都是我第一次用!所以有很多问题自己找不出来!
#include <stdio.h>
#include <stdlib.h>
#define M 100
#define N 100
#include <conio.h>

struct student
{
int r[M][N];
}name;

int main(void)
{
int i, j, m, n, p, s ,k = 0;
struct student *p1;
struct student *p2;
struct student *p3;
int print(struct student *p3, int n, int s);

scanf("%d%d%d%d", &m, &n, &p, &s);
for(i = 1;i <= m;i ++)
{
p1 = (struct student*)malloc(sizeof(struct student));
p2 = (struct student*)malloc(sizeof(struct student));
p3 = (struct student*)malloc(sizeof(struct student));
for(i = 0;i < n;i ++)
for(j = 0;j < p;j ++)
{
scanf("%d", &p1->r[i][j]);
}
for(i = 0;i < p;i ++)
for(j = 0;j < s;j ++)
{
scanf("%d", &p2->r[i][j]);
}
for(i = 0;i < n;i ++)
{
for(j = 0;j < p;j ++)
{
p3->r[i][k] += p1->r[i][j]*p2->r[j][k];
}
k ++;
p3->r[i][k] = 0;
}
print(p3, n, s);
free(p1);
free(p2);
free(p3);

getch();


}

return 0;
}

int print(struct student *p3, int n, int s)
{
int i, j;
for(i = 0;i < n;i ++)
{
for(j = 0;j < s;j ++)
printf("%d", p3->r[i][j]);
printf("\n");
}

return 0;
}


该学习了。。。
2006-12-04 18:56
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
得分:0 

A Contesting Decision
Judging a programming contest is hard work, with demanding contestants, tedious decisions, and monotonous work. Not to mention the nutritional problems of spending 12 hours with only donuts, pizza, and soda for food. Still, it can be a lot of fun.

Software that automates the judging process is a great help, but the notorious unreliability of some contest software makes people wish that something better were available. You are part of a group trying to develop better, open source, contest management software, based on the principle of modular design.

Your component is to be used for calculating the scores of programming contest teams and determining a winner. You will be given the results from several teams and must determine the winner.

Scoring

There are two components to a team's score. The first is the number of problems solved. The second is penalty points, which reflects the amount of time and incorrect submissions made before the problem is solved. For each problem solved correctly, penalty points are charged equal to the time at which the problem was solved plus 20 minutes for each incorrect submission. No penalty points are added for problems that are never solved.

So if a team solved problem one on their second submission at twenty minutes, they are charged 40 penalty points. If they submit problem 2 three times, but do not solve it, they are charged no penalty points. If they submit problem 3 once and solve it at 120 minutes, they are charged 120 penalty points. Their total score is two problems solved with 160 penalty points.

The winner is the team that solves the most problems. If teams tie for solving the most problems, then the winner is the team with the fewest penalty points.

Input

For the programming contest your program is judging, there are four problems. You are guaranteed that the input will not result in a tie between teams after counting penalty points.

Line 1 <nTeams>
Line 2-n+1 <Name> <p1Sub> <p1Time> <p2Sub> <p2Time> ... <p4Time>

The first element on the line is the team name, which contains no whitespace. Following that, for each of the four problems, is the number of times the team submitted a run for that problem and the time at which it was solved correctly (both integers). If a team did not solve a problem, the time will be zero. The number of submissions will be at least one if the problem was solved.

Output

The output consists of a single line listing the name of the team that won, the number of problems they solved, and their penalty points.

Sample Input
4
Stars 2 20 5 0 4 190 3 220
Rockets 5 180 1 0 2 0 3 100
Penguins 1 15 3 120 1 300 4 0
Marsupials 9 0 3 100 2 220 3 80

Sample Output
Penguins 3 475


该学习了。。。
2006-12-05 18:45
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
得分:0 

写的头都大了!谁能帮看看是哪里错了!
#include <stdio.h>
#include <stdlib.h>
#define N 100
#define M 100
#define T 100

struct student
{
char str[N];
int problem1;
int score1;
int problem2;
int score2;
int problem3;
int score3;
int problem4;
int score4;
}name;

int main(void)
{
int n, i, sum[M];
struct student * p[T];
int array(int a);
int cal(struct student *p[], int sum[], int n);

scanf("%d", &n);
i = 0;
for(i = 0;i < n;i ++)
{
p[i] = (struct studnt *)malloc(sizeof(struct student));
scanf("%s%d%d%d%d%d%d%d%d", p[i]->str, &p[i]->problem1, &p[i]->score1, &p[i]->problem2, &p[i]->score2, &p[i]->problem3, &p[i]->score3, &p[i]->problem4, &p[i]->score4);
sum[i] = array(p[i]->score1) + array(p[i]->score2) + array(p[i]->score3) + array(p[i]->score4);
}
cal(p, sum, n);
for(i = 0;i < n;i ++)
{
free(p[i]);
}

return 0;

}

int array(int a)
{
if(a == 0)
return 0;
return 1;
}

int cal(struct student *p[], int sum[], int n)
{
int i = 0, min = 0, num = 0, abc[N];
int show(int a[], int n, struct student * p[T]);

for(i = 0;i < n;i ++)
{
if(sum[i] > min)
{
min = sum[i];
}
}
for(i = 0;i < n;i ++)
{
if(min - sum[i] == 0)
{
abc[num] = i;
num ++;
}
}
show(abc, num, p);

return 0;
}

int show(int a[], int num, struct student * p[T])
{

int print(struct student *p[], int m, int k);
int jisuan(int a, struct student * p[T]);
int i, max = 0, k, shuxu;

if(num == 1)
{
print(p,a[num], k);
}
else
{
for(i = 0;i < num;i ++)
{
k = jisuan(a[num], p);
if(k > max)
{
max = k;
shuxu = i;
}
}
print(p, i, k);
}

return 0;
}

int jisuan(int a, struct student * p[])
{
int sum = 0;

sum = (p[a]->problem1 - 1)*20 + p[a]->score1 + (p[a]->problem2 - 1)*20 + p[a]->score2 + (p[a]->problem3 - 1)*20 + p[a]->score3 + (p[a]->problem4 - 1)*20 + p[a]->score4;

return sum;

}

int print(struct student *p[], int m, int k)
{
printf("%s %d", p[m]->str, k);

return 0;

}


该学习了。。。
2006-12-06 16:18
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
得分:0 

int main(void)
{
int n, i, sum[M];
struct student * p[T];
int array(int a);
int cal(struct student *p[], int sum[], int n);

scanf("%d", &n);在这里我在调试的时候,为什么n的值读入的值呢!i的值也是!它不是零,而是一个很大的数!
i = 0;
for(i = 0;i < n;i ++)
{
p[i] = (struct studnt *)malloc(sizeof(struct student));
scanf("%s%d%d%d%d%d%d%d%d", p[i]->str, &p[i]->problem1, &p[i]->score1, &p[i]->problem2, &p[i]->score2, &p[i]->problem3, &p[i]->score3, &p[i]->problem4, &p[i]->score4);
sum[i] = array(p[i]->score1) + array(p[i]->score2) + array(p[i]->score3) + array(p[i]->score4);
}
cal(p, sum, n);
for(i = 0;i < n;i ++)
{
free(p[i]);
}

return 0;

}


该学习了。。。
2006-12-06 16:33
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
得分:0 

终于通过了!
#include <stdio.h>
#include <stdlib.h>
#define N 50
#define M 10


struct student
{
char str[N];
int problem1;
int score1;
int problem2;
int score2;
int problem3;
int score3;
int problem4;
int score4;
}name[N];

int main(void)
{
int n, i = 0, sum[M];
int array(int a);
int cal(struct student name[N], int sum[], int n);

scanf("%d", &n);
for(i = 0;i < n;i ++)
{
scanf("%s%d%d%d%d%d%d%d%d", name[i].str, &name[i].problem1, &name[i].score1, &name[i].problem2, &name[i].score2, &name[i].problem3, &name[i].score3, &name[i].problem4, &name[i].score4);
sum[i] = array(name[i].score1) + array(name[i].score2) + array(name[i].score3) + array(name[i].score4);
}
cal(name, sum, n);

return 0;

}

int array(int a)
{
if(a == 0)
return 0;
return 1;
}

int cal(struct student name[N], int sum[], int n)
{
int i = 0, min = 0, num = 0, abc[N];
int show(int a[], int n, struct student name[N], int min);

for(i = 0;i < n;i ++)
{
if(sum[i] > min)
{
min = sum[i];
}
}
for(i = 0;i < n;i ++)
{
if(min - sum[i] == 0)
{
abc[num] = i;
num ++;
}
}
show(abc, num, name, min);

return 0;
}

int show(int a[], int num, struct student name[N], int min)
{

int print(struct student name[N], int m, int k, int min);
int jisuan(int a, struct student name[N]);
int i, max = 100000, k, shuxu;

if(num == 1)
{
k = jisuan(a[num], name);
print(name,a[num], k, min);
}
else
{
for(i = 0;i < num;i ++)
{
k = jisuan(a[i], name);
if(k < max)
{
max = k;
shuxu = i;
}
}
print(name, shuxu + 1, max, min);
}

return 0;
}

int jisuan(int a, struct student name[N])
{
int array(int a);
int sum = 0;

sum = (name[a].problem1 - 1)*20*array(name[a].score1) + name[a].score1 + (name[a].problem2 - 1)*20*array(name[a].score2) + name[a].score2 + (name[a].problem3 - 1)*20*array(name[a].score3) + name[a].score3 + (name[a].problem4 - 1)*20*array(name[a].score4) + name[a].score4;

return sum;

}

int print(struct student name[N], int m, int k, int min)
{
printf("%s %d %d\n", name[m].str, min, k);

return 0;

}



该学习了。。。
2006-12-06 18:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-106983-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.117763 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved