ZOJ-2316-鄙视浙大的OJ
2015-03-10 22:56
309 查看
以前一直都是在POJ上面刷,今年要报ACM ICPC只好在自己学校的OJ上面刷,2316这道题真坑,最开始线性代数上面aij指的是第i行j列的元素,这道题居然是第j行i列,出题者你学过线代吗?害我笔算程序算,算好多遍都和sample output不一样!然后就是该死的格式,什么叫输出块之间空一行,最开始第一行空了,WA,后来又WA,原来最后一行也不能空,我去,从没见过这么严格的OJ,而且这东西有什么意义啊!另:今天起入住CSDN写博客啦~
question:
Matrix Multiplication
Time Limit: 2 Seconds Memory Limit: 32768 KB
Let us consider undirected graph G = which has N vertices and M edges. Incidence matrix of this graph is N * M matrix A = {aij}, such that aij is 1 if i-th vertex
is one of the ends of j-th edge and 0 in the other case. Your task is to find the sum of all elements of the matrix ATA.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank
line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
The first line of the input file contains two integer numbers - N and M (2 <= N <= 10 000, 1 <= M <= 100 000). 2M integer numbers follow, forming M pairs, each pair describes one edge
of the graph. All edges are different and there are no loops (i.e. edge ends are distinct).
Output
Output the only number - the sum requested.
Sample Input
1
4 4
1 2
1 3
2 3
2 4
Sample Output
18
code:
#include <iostream>
#include <memory.h>
#include <stdio.h>
using namespace std;
int main()
{
int a[10001];
int repeat, n, m;
int v1, v2;
int sum;
cin >> repeat;
for (int r = 0; r<repeat; r++)
{
memset(a, 0, sizeof(a));
cin >> n >> m;
sum = 0;
for (int i = 0; i<m; i++)
{
cin >> v1 >> v2;
a[v1]++;
a[v2]++;
}
for (int q = 1; q<=n; q++)
{
sum += a[q] * a[q];
}
cout << sum << endl;
if (r<repeat-1)cout << endl;
}
}
question:
Matrix Multiplication
Time Limit: 2 Seconds Memory Limit: 32768 KB
Let us consider undirected graph G = which has N vertices and M edges. Incidence matrix of this graph is N * M matrix A = {aij}, such that aij is 1 if i-th vertex
is one of the ends of j-th edge and 0 in the other case. Your task is to find the sum of all elements of the matrix ATA.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank
line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
The first line of the input file contains two integer numbers - N and M (2 <= N <= 10 000, 1 <= M <= 100 000). 2M integer numbers follow, forming M pairs, each pair describes one edge
of the graph. All edges are different and there are no loops (i.e. edge ends are distinct).
Output
Output the only number - the sum requested.
Sample Input
1
4 4
1 2
1 3
2 3
2 4
Sample Output
18
code:
#include <iostream>
#include <memory.h>
#include <stdio.h>
using namespace std;
int main()
{
int a[10001];
int repeat, n, m;
int v1, v2;
int sum;
cin >> repeat;
for (int r = 0; r<repeat; r++)
{
memset(a, 0, sizeof(a));
cin >> n >> m;
sum = 0;
for (int i = 0; i<m; i++)
{
cin >> v1 >> v2;
a[v1]++;
a[v2]++;
}
for (int q = 1; q<=n; q++)
{
sum += a[q] * a[q];
}
cout << sum << endl;
if (r<repeat-1)cout << endl;
}
}
相关文章推荐
- 九度OJ 1006 ZOJ问题 (这题測试数据有问题)
- 九度1006 ZOJ问题 浙大考研机试题
- 浙大ZOJ PAT practice - 1001
- zoj 2316 Matrix Multiplication(2-D)
- ZOJ - 2316 Matrix Multiplication(模拟)
- ZOJ 2316 Matrix Multiplication(找规律)(矩阵和它的转置矩阵之积)
- hdu-oj ZOJ问题
- 浙大ZOJ 1005 Jugs问题解决
- 浙大ZOJ 1009 Enigma问题解决及别人的解决方案
- ACM Hrbeu OJ 1201 Simplest Task in Windows || ZOJ 2480
- OJ_1006 ZOJ问题
- zoj 2316 Matrix Multiplication(D)
- ZOJ 2316 Matrix Multiplication(找规律)(矩阵和它的转置矩阵之积)
- 浙大ZOJ 1006 Do the Untwist问题解决及其他人的解决方法
- ZOJ 3890 Wumpus (2015年7月浙大月赛、广搜)
- zoj_3882_7/27浙大月赛B
- ZOJ 3521 Fairy Wars oj错误题目,计算几何,尺取法,排序二叉树,并查集 难度:2
- ZOJ-3956-Course Selection System【01背包】【17th浙大校赛】
- zoj 2316 Matrix Multiplication(2-D)
- ZOJ - 2316 Matrix Multiplication