zoukankan      html  css  js  c++  java
  • toj 2968 Find the Diagonal

    2968.   Find the Diagonal
    Time Limit: 1.0 Seconds   Memory Limit: 65536K
    Total Runs: 695   Accepted Runs: 223



    A square matrix contains equal number of rows and columns. If the order of the matrix is known it can be calculated as in the following format:
    Order: 3

    Order: 5

    and so on..

    Now look at the diagonals of the matrices. In the second matrix - the elements of a diagonal are marked with circles but this is not the only one in this matrix but there are some other minor diagonals like <6, 12, 18, 24> as well as <2, 8, 14, 20> and many others.

    Input

    Each input line consists of two values. The first value is the order of the matrix and the later is an arbitrary element of that matrix. The maximum element of the matrix will fit as a 32-bit integer.

    Output

    Each output line will display the diagonal elements of the matrix containing the given input element.

    Sample Input

    4 5
    5 11
    10 81
    

    Sample Output

    5 10 15
    11 17 23
    81 92
    

    Samina Azad (CSE-03)



    Source: CUET Easy Contest
    Submit   List    Runs   Forum   Statistics

    #include <iostream>
    using namespace std;
    int m , n , a1;

    int a(int i)
    {
      
    return a1 + (n + 1* (i - 1);
    }

    int main()
    {
      
    int i;
    start:  
    while (cin >> n >> m)
      {
        
    while (1)
        {
          
    if ((m - 1% n == 0 || m <= n)
          {
            a1 
    = m;
            
    break;
          }
          
    else
              m 
    -= n + 1;
        }
        cout 
    << a1 ;
      
    if (a1 % n == 0)
      {
        cout 
    << endl;
        
    goto start;
      }
        
    for (i = 2 ; ; ++ i)
        {
          
    int mm = a(i); 
          
    if (mm <= n * n)
          {
            cout 
    << " " << mm;
            
    if (mm % n == 0)
                
    break;
          }
          
    else
              
    break;
        }
        cout 
    << endl;
      }
      
    return 0;
    }
  • 相关阅读:
    Jmeter+Jenkins持续集成(三、集成到Jenkins)
    Jmeter+Jenkins持续集成(一、环境准备)
    Git----基础常用的命令总结
    -第5章 多级菜单
    -第4章 变幻菜单
    -第3章 jQuery方法实现下拉菜单显示和隐藏
    -第2章 JS方法实现下拉菜单显示和隐藏
    DIV+CSS+PS实现背景图的三层嵌套以及背景图的合并
    -第1章 HTMLCSS方法实现下拉菜单
    前端常用效果-目录
  • 原文地址:https://www.cnblogs.com/forever4444/p/1460363.html
Copyright © 2011-2022 走看看