11470 - Square Sums
Moderator: Board moderators
11470 - Square Sums
This post is not about asking for help so much as sharing approaches:
I travel the given square in a spiral-way adding the integers I find. When I get to a visited cell I tried to turn right and continue. After visiting all cells I stop.
Every time I turn and I'm facing right I store the value of the sum and then reset it to 0.
To make the travel I frame the square with -1 and visited cells are marked with -1 as well. I move in the actual direction until I reach a -1. From RIGHT I turn DOWN, then LEFT then UP and RIGHT again.
Anyone did something different than the spiral traveling? If you did a spiral traveling, how did you do it?
I travel the given square in a spiral-way adding the integers I find. When I get to a visited cell I tried to turn right and continue. After visiting all cells I stop.
Every time I turn and I'm facing right I store the value of the sum and then reset it to 0.
To make the travel I frame the square with -1 and visited cells are marked with -1 as well. I move in the actual direction until I reach a -1. From RIGHT I turn DOWN, then LEFT then UP and RIGHT again.
Anyone did something different than the spiral traveling? If you did a spiral traveling, how did you do it?
Re: 11470 - Square Sums
I simultaneously added top and bottom rows of each ring and then left and right columns of the rings, excluding the numbers that belong both to the top and botom rows.
Here's the relevant part of my code:
Here's the relevant part of my code:
Code: Select all
printf("Case %d:", C++);
for (int i=0; i<(n/2); ++i){
int s = 0;
for (int j=i; j<=n-1-i; ++j){
s += g[i][j];
s += g[n-1-i][j];
}
for (int k=i+1; k<n-1-i; ++k){
s += g[k][i];
s += g[k][n-1-i];
}
printf(" %d", s);
}
if (n & 1) printf(" %d", g[n/2][n/2]);
Runtime errors in Pascal are reported as Wrong Answers by the online judge. Be careful.
Are you dreaming right now?
http://www.dreamviews.com
Are you dreaming right now?
http://www.dreamviews.com
-
- New poster
- Posts: 12
- Joined: Wed Aug 18, 2010 12:07 pm
Re: 11470 - Square Sums
Why RE?? Please help me.
11470-Square Sums
![:cry:](./images/smilies/icon_cry.gif)
![:cry:](./images/smilies/icon_cry.gif)
I tried almost 20 or more test data and it was all right!
but Judge says it's wrong!!
please give me some critical test data.
Sorry about my bad english.
and here is my code....
Code: Select all
Thank you sazzadcsedu, I got AC.
Last edited by mintae71 on Thu Sep 09, 2010 11:05 am, edited 1 time in total.
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 11470-Square Sums
Try this-
Do not create a new thread when already it is existing.
Code: Select all
8
23 434 555 6666 656 666 67 12
654 44 55 7676 888 866 343 77
98 77 4454 544 88 99 343 5454
5454 54 55 55 66 77 55 22
979 787 77 33 555 666 888 666
87678 676 55 666 454 766 99 67786
76786 77876 87 777 55465 5465 887 343
786 22 655 55 77 6565 77 88
0
output:
Case 1: 263401 153408 8001 709
your output:
Case 1: 263401 153408 8001 709 33
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 11470-Square Sums
sazzadcsedu, I changed my code and It works......
But why OJ says NO........
Can you please help one more time?
Thank you~
![:lol:](./images/smilies/icon_lol.gif)
![:D](./images/smilies/icon_biggrin.gif)
But why OJ says NO........
![:cry:](./images/smilies/icon_cry.gif)
![:cry:](./images/smilies/icon_cry.gif)
![:cry:](./images/smilies/icon_cry.gif)
![:cry:](./images/smilies/icon_cry.gif)
![:cry:](./images/smilies/icon_cry.gif)
![:cry:](./images/smilies/icon_cry.gif)
![:cry:](./images/smilies/icon_cry.gif)
Can you please help one more time?
Thank you~
![:lol:](./images/smilies/icon_lol.gif)
![:lol:](./images/smilies/icon_lol.gif)
Code: Select all
Thank you sazzadcsedu, I got AC.
getting WA at uva=11470;http://uva.onlinejudge.org/external/
why i am getting WA..........?????
thnkz again brianfry713 Got AC....many many thnkz
thnkz again brianfry713 Got AC....many many thnkz
Last edited by graph_dp on Fri Jan 04, 2013 11:28 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: getting WA at uva=11470;http://uva.onlinejudge.org/exter
Doesn't match the sample I/O, you shouldn't be printing len1.
Check input and AC output for thousands of problems on uDebug!
Re: 11470-Square Sums
Why i am getting WA????![]()
Code: Select all
#include <stdio.h>
int main()
{
long long int ara[100][100],sqval[10000];
long long int n,i,j,i1,j1,x,x1,y,y1,z,t,nsq,c,s1,s2,s3,s4,sum;
for(t=0;;)
{
scanf("%d",&n);if(n==0) break;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%lld",&ara[i][j]);
}
}
if(n%2==0) nsq=n/2;
else nsq=(n+1)/2;
for(c=0;c<nsq;c++)
{
for(y=c,s1=0,s2=0;y<n-c;y++) {s1=s1+ ara[c][y]; s2=s2+ ara[n-1-c][y];}
for(x=c,s3=0,s4=0;x<n-c;x++) { s3=s3+ara[x][c];s4=s4+ara[x][n-1-c]; }
if(c!=nsq-1) sum=s1+s2+s3+s4-ara[c][c]-ara[n-1-c][c]-ara[c][n-1-c]-ara[n-1-c][n-1-c];
else if(c==nsq-1 && (c+1) %2!=0) sum=s1;
else if(c==nsq-1 && (c+1) % 2==0 ) sum=s1+s2+s3+s4-ara[c][c]-ara[n-1-c][c]-ara[c][n-1-c]-ara[n-1-c][n-1-c];
sqval[c]=sum;
}
t++;
printf("Case %lld: ",t);
for(z=0;z<nsq;z++)
{
printf("%lld",sqval[z]);
if(z!=nsq-1) { printf(" "); }
}
printf("\n");
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11470-Square Sums
Try using scanf("%lld", &n) on line 8.
Check input and AC output for thousands of problems on uDebug!