ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1319. Hotel

here is the mathematic method
Posted by esger 30 Apr 2008 15:21
#include<iostream.h>
int  i,j;
long a[101][101],n;
 int main(){
    cin>>n;
   for(i=1;i<n+1;i++)
 {   a[i][n]=i*(i+1)/2;
  }
   for(i=1;i<n;i++)
 {  for(j=n-1;j>=i;j--)
  {  a[i][j]=a[i][j+1]+n-j+i-1;
   }
 }
   for(i=2;i<n+1;i++)
 {  for(j=i-1;j>0;j--)
  {  a[i][j]=a[i][j+1]+n+j-i;
   }
 }
   for(i=1;i<n+1;i++)
 { for(j=1;j<n+1;j++)
    cout<<a[i][j]<<" ";
    cout<<"\n";
  }
 return 0;
}
Re: here is the mathematic method
Posted by ENick(TNU) 2 May 2008 18:58
This method is easy but very interesting!
Re: here is the mathematic method
Posted by null 10 Oct 2011 08:33
Nice, but there's no need in arrays if you're trying to use some math. My solution uses just seven integers and that's enough.