11349 - Symmetric Matrix
Moderator: Board moderators
Re: 11349 - Symmetric Matrix
Surprisingly executing the same code in my windows XP PC gives the proper output and I think it is because of fflush(stdin) statement which is platform dependent. So for the platforms not supporting fflush (stdin) the input logic fails and hence the code. Thanks for pointing it out, I changed the input logic and got AC
Re: 11349 - Symmetric Matrix
fflush(stdin) is a no-op in every sane programming environment, because fflush is only supposed to flush stream's *output* buffers.
But Microsoft's runtime library went totally nuts and defines it as discarding stream's input buffer as well. Well, usually it is a mistake to want to discard input buffers – or you'll risk throwing away the stuff you care about. Remember that the judge gives you the whole input at once from a file. Nobody's sitting there and typing the input line-by-line, as you might do in your own environment.
But Microsoft's runtime library went totally nuts and defines it as discarding stream's input buffer as well. Well, usually it is a mistake to want to discard input buffers – or you'll risk throwing away the stuff you care about. Remember that the judge gives you the whole input at once from a file. Nobody's sitting there and typing the input line-by-line, as you might do in your own environment.
Re: 11349 - Symmetric Matrix
This problem is not difficult, but I cannot seem to get ACC. (WA always).
Here's my code, kindly check it out?
Here's my code, kindly check it out?
Code: Select all
Accepted. I was forgetting the '.' at the end xD
Re: 11349 - Symmetric Matrix
Ahh....very tricky and very nice The range of the integers are 2^32 <= Mij <= 2^32, so you must use long long int. I got Wrong Answer twice because of this . And remember to include a '.' at the end of all your results. Also remember that if any of the numbers is negative, then the matrix is non-symmetrical. For example:
The result for this one is non-symmetrical.
Code: Select all
1
N = 3
-5 -1 -3
-2 0 -2
-3 -1 -5
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11349 - Symmetric Matrix
Input:Correct output:
Code: Select all
1
n = 1
-1
Code: Select all
Test #1: Non-symmetric.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 1
- Joined: Mon Apr 22, 2013 1:22 am
11349 - Symmetric Matrix why WA
#include <iostream>
using namespace std;
int main()
{
bool x = true;
int testcases;
cin>>testcases;
for(int t=1 ; t<=testcases; t++)
{
char Nu , eq ;
int N ;
cin>>Nu; cin>>eq ;cin>>N;
long** matrix = new long*[N];
for(int k = 0 ; k<N; k++)
matrix[k] = new long[N];
for(int i=0 ; i<N ; i++)
{
for (int j=0 ; j<N ; j++)
{
cin>>matrix[j];
}
}
for(int i=0 ; i<N ; i++)
{
for(int j=0 ; j<N ; j++)
{
if (matrix[j] < 0 )
{
x =false ;
break;
}
}
if(x == false)
break;
}
if (x==false)
{
cout<<"Test #"<<t<<": Non-symmetric."<<endl;
}
else
{
for(int i=0 ; i<N ; i++)
{
for(int j=0 ; j<N; j++)
{
if(matrix[j] == matrix[N-(i+1)][N-(j+1)])
x=true;
else
{
x=false;
break;
}
}
if(x == false)
break;
}
if(x)
cout<<"Test #"<<t<<": Symmetric."<<endl;
else
cout<<"Test #"<<t<<": Non-symmetric."<<endl;
}
for(int i=0 ; i<N ; i++)
delete []matrix;
delete []matrix;
}
return 0;
}
using namespace std;
int main()
{
bool x = true;
int testcases;
cin>>testcases;
for(int t=1 ; t<=testcases; t++)
{
char Nu , eq ;
int N ;
cin>>Nu; cin>>eq ;cin>>N;
long** matrix = new long*[N];
for(int k = 0 ; k<N; k++)
matrix[k] = new long[N];
for(int i=0 ; i<N ; i++)
{
for (int j=0 ; j<N ; j++)
{
cin>>matrix[j];
}
}
for(int i=0 ; i<N ; i++)
{
for(int j=0 ; j<N ; j++)
{
if (matrix[j] < 0 )
{
x =false ;
break;
}
}
if(x == false)
break;
}
if (x==false)
{
cout<<"Test #"<<t<<": Non-symmetric."<<endl;
}
else
{
for(int i=0 ; i<N ; i++)
{
for(int j=0 ; j<N; j++)
{
if(matrix[j] == matrix[N-(i+1)][N-(j+1)])
x=true;
else
{
x=false;
break;
}
}
if(x == false)
break;
}
if(x)
cout<<"Test #"<<t<<": Symmetric."<<endl;
else
cout<<"Test #"<<t<<": Non-symmetric."<<endl;
}
for(int i=0 ; i<N ; i++)
delete []matrix;
delete []matrix;
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11349 - Symmetric Matrix why WA
Use long long.
Check input and AC output for thousands of problems on uDebug!
Re: 11349 - Symmetric Matrix
Here's some input I found useful during testing / debugging.
Input:
AC Output:
Input:
Code: Select all
8
N = 3
5 1 3
2 -5 2
3 1 5
N = 4
4294967296 87 1 3
2 88 2 21
21 2 88 2
3 1 87 4294967296
N = 1
-1
N = 1
66
N = 2
4 5
5 4
N = 5
5 1 3 2 99
2 5 2 1 2
987 77 66 78 987
2 1 2 5 2
99 2 3 1 5
N = 5
5 1 3 2 99
2 5 2 1 2
987 77 66 77 987
2 1 2 5 2
99 2 3 1 5
N = 5
5 1 3 2 99
2 5 2 1 2
987 77 -66 78 987
2 1 2 5 2
99 2 3 1 5
Code: Select all
Test #1: Non-symmetric.
Test #2: Symmetric.
Test #3: Non-symmetric.
Test #4: Symmetric.
Test #5: Symmetric.
Test #6: Non-symmetric.
Test #7: Symmetric.
Test #8: Non-symmetric.
Re: 11349 - Symmetric Matrix
@ v1n1t
why case 6 is non-symmetric???
why case 6 is non-symmetric???
Re: 11349 - Symmetric Matrix
why case 6 is non symmetric???v1n1t wrote:Here's some input I found useful during testing / debugging.
Input:AC Output:Code: Select all
8 N = 3 5 1 3 2 -5 2 3 1 5 N = 4 4294967296 87 1 3 2 88 2 21 21 2 88 2 3 1 87 4294967296 N = 1 -1 N = 1 66 N = 2 4 5 5 4 N = 5 5 1 3 2 99 2 5 2 1 2 987 77 66 78 987 2 1 2 5 2 99 2 3 1 5 N = 5 5 1 3 2 99 2 5 2 1 2 987 77 66 77 987 2 1 2 5 2 99 2 3 1 5 N = 5 5 1 3 2 99 2 5 2 1 2 987 77 -66 78 987 2 1 2 5 2 99 2 3 1 5
Code: Select all
Test #1: Non-symmetric. Test #2: Symmetric. Test #3: Non-symmetric. Test #4: Symmetric. Test #5: Symmetric. Test #6: Non-symmetric. Test #7: Symmetric. Test #8: Non-symmetric.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11349 - Symmetric Matrix
In the third row 77 != 78
Check input and AC output for thousands of problems on uDebug!
Re: 11349 - Symmetric Matrix
Repeating your question doesn't make someone answer it quicker.jokerz wrote:why case 6 is non symmetric???
Thank you for helping make things clear.brianfry713 wrote:In the third row 77 != 78
-
- New poster
- Posts: 15
- Joined: Tue Oct 21, 2014 4:08 pm
- Location: Bangladesh
- Contact:
Re: 11349 - Symmetric Matrix
removed after ac