Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <iostream>
- using namespace std;
- ifstream fin("tinta.in");
- ofstream fout("tinta.out");
- vector< vector<int> > a;
- int suma(int i,int j)
- {
- int s=a[i][j+1]+a[i][j-1]+a[i+1][j]+a[i-1][j]+a[i-1][j-1]+a[i+1][j-1]+a[i+1][j+1]+a[i-1][j+1];
- return s;
- }
- int main()
- {
- int n,i=1,j=1,x=1,s;
- vector<int> temp;
- fin>>n;
- for(i=0; i<=n; i++)
- {
- temp.clear();
- for(j=0; j<=n; j++)
- temp.push_back(-1);
- temp.push_back(0);
- temp.push_back(0);
- a.push_back(temp);
- }
- temp.clear();
- for(j = 0; j <= n; j++)
- temp.push_back(0);
- a.push_back(temp);
- temp.clear();
- for(j = 0; j <= n; j++)
- temp.push_back(0);
- a.push_back(temp);
- i=1;
- j=1;
- // cerr << "ok1\n";
- while(i+j<=n+1)
- {
- if((i+j)%2)
- {
- for(s=1; s<=i+j-1; s++)
- a[i++][j--]=x++;
- j++;
- }
- else
- {
- for(s=1; s<=i+j-1; s++)
- a[i--][j++]=x++;
- i++;
- }
- }
- // cerr << "ok2\n";
- x--;
- while(i+j<=2*n)
- {
- cerr << i << ' ' << j << ' ' << x << '\n';
- if((i+j)%2)
- {
- for(s=1; s<=i+j-1; s++)
- {
- a[i++][j--]=x++;
- if(a[i][j]==0)
- break;
- }
- j++;
- x--;
- }
- else
- {
- for(s=1; s<=i+j-1; s++)
- {
- a[i--][j++]=x++;
- if(a[i][j]==0)
- break;
- }
- x--;
- i++;
- }
- }
- // cerr << "ok3\n";
- for(i=1; i<=n; i++)
- {
- for(j=1; j<=n; j++)
- fout<<a[i][j]<<' ';
- fout<<endl;
- }
- fout<<n+n-5<<endl;
- for(j=2; j<=n-1; j++)
- fout<<suma(2,j)<<' ';
- for(i=3; i<=n-1; i++)
- fout<<suma(i,n-1)<<' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement