11360 - Have Fun with Matrices

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

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11360 - Have Fun with Matrices

brianfry713,

Thanks for the great test case.

How did you generate these? Did you write a program to do this?
Last edited by uDebug on Thu Mar 27, 2014 9:14 am, edited 1 time in total.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11360 - Have Fun with Matrices

plamplam wrote:You have to take the operations(for example inc, transpose, row a b etc) using scanf("%s");.When I tried with gets() the judge blessed me with a "Wrong Answer"
All I did was use

Code: Select all

``getline(cin, aLine);``
where "aLine" is of type std::string and then check "aLine[0]" - with the first character of the operation to be performed.

For the switch operations, I added the following lines

Code: Select all

``````istringstream ss(aLine);
ss >> aLine >> a >> b;``````
where "a" and "b" are of type integers.

In other words, there's nothing fancy going on with the judge's input.

If your code passes brianfry713's exhaustive test case, you should be good.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

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

Re: 11360 - Have Fun with Matrices

I often write a program using rand() to generate test cases.
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: 11360 - Have Fun with Matrices

brianfry713 wrote:I often write a program using rand() to generate test cases.
Great stuff! Thanks for sharing.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11360 - Have Fun with Matrices

Getting TLE ! What should I do to get rid of it? Here is my code:

Code: Select all

``````#include<stdio.h>
struct matrix
{
int col[15];
int cl[15];
};
int main()
{
int t,n,c,comand,i,j,k,x,y,temp;
char oper[12];
struct matrix row[15];
struct matrix rw[15];
scanf("%d",&t);
for(c=1;c<=t;c++)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&row[i].col[j]);
}
}
scanf("%d",&comand);
getchar();
while(comand--)
{
gets(oper);
if(oper[0]=='i')
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
row[i].col[j]++;
}
}
}
else if(oper[0]=='d')
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
row[i].col[j]--;
}
}
}
else if(oper[0]=='r')
{
x=oper[4]-'0';
y=oper[6]-'0';
for(i=1;i<=n;i++)
{
temp=row[x].col[i];
row[x].col[i]=row[y].col[i];
row[y].col[i]=temp;
}
}
else if(oper[0]=='c')
{
x=oper[4]-'0';
y=oper[6]-'0';
for(i=1;i<=n;i++)
{
temp=row[i].col[x];
row[i].col[x]=row[i].col[y];
row[i].col[y]=temp;
}
}
else if(oper[0]=='t')
{
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
rw[i].cl[j]=row[i].col[j];
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
row[i].col[j]=rw[j].cl[i];
}
}
}
}
printf("Case %d#\n",c);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(j!=1)
printf(" ");
printf("%d",row[i].col[j]);
}
printf("\n");
}
printf("\n");
}
return 0;
}
``````
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

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

Re: 11360 - Have Fun with Matrices

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11360 - Have Fun with Matrices

Code: Select all

``Accepted!!``
Last edited by Shahidul.CSE on Thu Aug 28, 2014 5:09 am, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

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

Re: 11360 - Have Fun with Matrices

Try input:

Code: Select all

``````1
1
9
11
inc
inc
inc
inc
inc
inc
inc
inc
inc
inc
inc
``````
Output should be 0
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 11360 - Have Fun with Matrices

brianfry713 wrote:Try input:

Code: Select all

``````1
1
9
11
inc
inc
inc
inc
inc
inc
inc
inc
inc
inc
inc
``````
Output should be 0
Thanks, Got AC!!
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com