3 solutions

  • 10
    @ 2024-3-21 16:36:03
    /*
    观察每个对角线的起点和每次填写的次数,按照右上到左下一次填数即可 
    
    */
    #include<bits/stdc++.h>
    using namespace std;
    const int N=20;
    int g[N][N];
    int main()
    {
    	int n;
    	cin>>n;
    	int cnt=1;
    	for(int i=1;i<=n;i++) //填写第i列的起点 
    	{
    		for(int x=1,y=i;x<=i;x++,y--) //从(1,i) 
    		{
    			g[x][y]=cnt++;
    		}
    	}
    	for(int i=1;i<=n;i++)
    	{
    		for(int j=1;j<=n-i+1;j++)
    		{
    			cout<<g[i][j]<<" ";
    		}
    		cout<<endl;
    	}
    	return 0;
    }
    
    
    
    • 1
      @ 2026-1-11 9:22:32
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      1
      
      • -4
        @ 2024-6-12 20:06:07
        #include<bits/stdc++.h>
        using namespace std;
        const int N=11;
        int n[N][N];
        int main(){
        	int qwert;
        	cin>>qwert;
        	int asdf=1;
        	for(int i=1;i<=qwert;i++)
        	{
        		int l=i;
        		int p=1;
        		while(l>=1)
        		{
        			n[p][l]=asdf;
        			asdf++;
        			p++;
        			l--;			
        		}
        	}
        	for(int q=1;q<=qwert;q++)
        	{
        		for(int d=1;d<=qwert;d++)
        		{
        			if(n[q][d]==0)
        			{
        				continue;
        			}
        			cout<<n[q][d]<<" ";
        		}
        		cout<<endl;
        	}
        	return 0;
        }
        
        
        • 1

        Information

        ID
        81
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        5
        Tags
        (None)
        # Submissions
        80
        Accepted
        42
        Uploaded By