Page 3 of 3
Re: 11360 - Have Fun with Matrices
Posted: Thu Mar 27, 2014 9:09 am
by uDebug
brianfry713,
Thanks for the great test case.
How did you generate these? Did you write a program to do this?
Re: 11360 - Have Fun with Matrices
Posted: Thu Mar 27, 2014 9:14 am
by uDebug
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
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.
Re: 11360 - Have Fun with Matrices
Posted: Thu Mar 27, 2014 9:23 pm
by brianfry713
I often write a program using rand() to generate test cases.
Re: 11360 - Have Fun with Matrices
Posted: Fri Mar 28, 2014 12:54 am
by uDebug
brianfry713 wrote:I often write a program using rand() to generate test cases.
Great stuff! Thanks for sharing.
Re: 11360 - Have Fun with Matrices
Posted: Fri Aug 15, 2014 10:53 am
by Shahidul.CSE
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;
}
Re: 11360 - Have Fun with Matrices
Posted: Sat Aug 16, 2014 12:55 am
by brianfry713
Try running your code on the sample input.
Re: 11360 - Have Fun with Matrices
Posted: Sun Aug 24, 2014 7:16 pm
by Shahidul.CSE
Re: 11360 - Have Fun with Matrices
Posted: Thu Aug 28, 2014 12:33 am
by brianfry713
Try input:
Code: Select all
1
1
9
11
inc
inc
inc
inc
inc
inc
inc
inc
inc
inc
inc
Output should be 0
Re: 11360 - Have Fun with Matrices
Posted: Thu Aug 28, 2014 5:10 am
by Shahidul.CSE
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!!
