Advertisement
nicuvlad76

Untitled

Feb 4th, 2023
776
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <fstream>
  2. #define N 105
  3. using namespace std;
  4. ifstream fin("tablou.in");
  5. ofstream fout("tablou.out");
  6. int a[N][N], v[N*N];
  7. int n, S;
  8.  
  9. int main()
  10. {
  11.     int i,j,k;
  12.     fin>>n>>S;
  13.     if( n*n*(n+1)/2>S){fout<<0; return 0;}
  14.     int s=S/n;
  15.     for(k=1; k*n+n*(n-1)/2<=s;k++);
  16.     k--;
  17.     int x=0;
  18.     for(i=1;i<=n;i++)
  19.     {
  20.         a[1][i]=k+i-1;
  21.         x+=a[1][i];
  22.     }
  23.     for(i=2;i<=n;i++)
  24.     {
  25.         for(j=1;j<n;j++)
  26.             a[i][j]=a[i-1][j+1];
  27.         a[i][n]=a[i-1][1];
  28.     }
  29.     S-=n*x;
  30.     x=S/n;
  31.     S%=n;
  32.     k=a[1][n]-x+1;
  33.     for(i=1;i<=n;i++)
  34.         for(j=1;j<=n;j++)
  35.         if(a[i][j]>=k)a[i][j]++;
  36.         else if(a[i][j]==k-1 && S>0)
  37.         {
  38.             a[i][j]++;
  39.             S--;
  40.         }
  41.     //afisare matrice
  42.     for(i=1;i<=n;i++,fout<<"\n")
  43.         for(j=1;j<=n;j++)
  44.             fout<<a[i][j]<<" ";
  45.     return 0;
  46. }
  47.  
Advertisement
Comments
  • jamesphlo
    1 year
    # text 0.47 KB | 0 0
    1. Super site! I am Loving it!! Will return once more. I'm taking your sustenance in addition. Thanks
    2. 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.
    3. 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.
    4. I like the valuable info in your articles.
Add Comment
Please, Sign In to add comment
Advertisement