Ural319(输出格式)

2015-07-20 17:13:13 ? 作者: ? 浏览: 3

?

?

解题思路:

分别从右上角和左下角考虑,和姐姐跟我说的上一题差不多·····

?

完整代码:

?

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include
          #include 
          
            using namespace std; typedef long long LL; const int MOD = int(1e9)+7; const int INF = 0x3f3f3f3f; const double EPS = 1e-9; const double PI = acos(-1.0); //M_PI; const int maxn = 101; int g[maxn][maxn]; int main() { #ifdef DoubleQ freopen(in.txt,r,stdin); #endif std::ios::sync_with_stdio(false); std::cin.tie(0); int n; while(cin >> n) { int key = 1; for(int k = n ; k >= 1 ; k --) { int i = 1; int j = k; g[i][j] = key; key ++; while(i + 1 <= n && j + 1 <= n) { j ++; i ++; g[i][j] = key; key ++; } } key = n * n; for(int k = 1 ; k <= n - 1 ; k ++) { int i = n; int j = k; g[i][j] = key; key --; while(i - 1 >= 1 && j - 1 >= 1) { i --; j --; g[i][j] = key; key --; } } for(int i = 1 ;i <= n ; i ++) { for(int j = 1; j <= n ; j ++) { cout << g[i][j] << ; } cout << endl; } } } 
          
        
       
      
     
    
   
  

?

-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: