11349 - Symmetric Matrix

All about problems in Volume 113. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

sharath
New poster
Posts: 6
Joined: Tue Sep 16, 2008 9:21 pm

Re: 11349 - Symmetric Matrix

Post by sharath »

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 :)
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 11349 - Symmetric Matrix

Post by mf »

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.
r2ro
New poster
Posts: 38
Joined: Thu Sep 25, 2008 9:26 am

Re: 11349 - Symmetric Matrix

Post by r2ro »

This problem is not difficult, but I cannot seem to get ACC. (WA always).

Here's my code, kindly check it out?

Code: Select all

Accepted. I was forgetting the '.' at the end xD
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 11349 - Symmetric Matrix

Post by plamplam »

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 :-? :oops: . 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:

Code: Select all

1
N = 3
-5 -1 -3
-2 0 -2
-3 -1 -5
The result for this one is non-symmetrical.
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson
shuvokr
Learning poster
Posts: 66
Joined: Tue Oct 02, 2012 8:16 pm
Location: Bangladesh

Re: 11349 - Symmetric Matrix

Post by shuvokr »

Remove after AC :D

Code: Select all

enjoying life ..... 
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11349 - Symmetric Matrix

Post by brianfry713 »

Input:

Code: Select all

1
n = 1
-1
Correct output:

Code: Select all

Test #1: Non-symmetric.
Check input and AC output for thousands of problems on uDebug!
ahmed mohamed said
New poster
Posts: 1
Joined: Mon Apr 22, 2013 1:22 am

11349 - Symmetric Matrix why WA

Post by ahmed mohamed said »

#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;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11349 - Symmetric Matrix why WA

Post by brianfry713 »

Use long long.
Check input and AC output for thousands of problems on uDebug!
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11349 - Symmetric Matrix

Post by uDebug »

Here's some input I found useful during testing / debugging.

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
AC Output:

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.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
jokerz
New poster
Posts: 8
Joined: Tue Nov 05, 2013 10:24 am

Re: 11349 - Symmetric Matrix

Post by jokerz »

@ v1n1t
why case 6 is non-symmetric???
jokerz
New poster
Posts: 8
Joined: Tue Nov 05, 2013 10:24 am

Re: 11349 - Symmetric Matrix

Post by jokerz »

v1n1t wrote:Here's some input I found useful during testing / debugging.

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
AC Output:

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.
why case 6 is non symmetric???
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11349 - Symmetric Matrix

Post by brianfry713 »

In the third row 77 != 78
Check input and AC output for thousands of problems on uDebug!
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11349 - Symmetric Matrix

Post by uDebug »

jokerz wrote:why case 6 is non symmetric???
Repeating your question doesn't make someone answer it quicker.
brianfry713 wrote:In the third row 77 != 78
Thank you for helping make things clear.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
Helaluddin_brur
New poster
Posts: 15
Joined: Tue Oct 21, 2014 4:08 pm
Location: Bangladesh
Contact:

Re: 11349 - Symmetric Matrix

Post by Helaluddin_brur »

removed after ac
Post Reply

Return to “Volume 113 (11300-11399)”