Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #define N 105
- using namespace std;
- ifstream fin("tablou.in");
- ofstream fout("tablou.out");
- int a[N][N], v[N*N];
- int n, S;
- int main()
- {
- int i,j,k;
- fin>>n>>S;
- if( n*n*(n+1)/2>S){fout<<0; return 0;}
- int s=S/n;
- for(k=1; k*n+n*(n-1)/2<=s;k++);
- k--;
- int x=0;
- for(i=1;i<=n;i++)
- {
- a[1][i]=k+i-1;
- x+=a[1][i];
- }
- for(i=2;i<=n;i++)
- {
- for(j=1;j<n;j++)
- a[i][j]=a[i-1][j+1];
- a[i][n]=a[i-1][1];
- }
- S-=n*x;
- x=S/n;
- S%=n;
- k=a[1][n]-x+1;
- for(i=1;i<=n;i++)
- for(j=1;j<=n;j++)
- if(a[i][j]>=k)a[i][j]++;
- else if(a[i][j]==k-1 && S>0)
- {
- a[i][j]++;
- S--;
- }
- //afisare matrice
- for(i=1;i<=n;i++,fout<<"\n")
- for(j=1;j<=n;j++)
- fout<<a[i][j]<<" ";
- return 0;
- }
Advertisement
Comments
-
- Super site! I am Loving it!! Will return once more. I'm taking your sustenance in addition. Thanks
- Thanks for sharing this information. I really like your blog post very much. You have really shared a informative and interesting blog post with people.
- This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
- I like the valuable info in your articles.
Add Comment
Please, Sign In to add comment
Advertisement