02: diagonal grids of the same column, 02 diagonal Grids

Source: Internet
Author: User

02: diagonal grids of the same column, 02 diagonal Grids
02: diagonal grids of the same column

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Input three natural numbers N, I, j (1 <= I <= N, 1 <= j <= N ), output in a N * N lattice Board (the columns and columns start from 1), with the position of all grids with the grid (I, j), the same column, and the same diagonal line.

For example, n = 4, I = 2, j = 3 indicates the lattice of the third column in the second row of the Board, for example:

First column

Column 2

Column 3

Column 4

 
       

First line

   

(2, 3)

 

Row 2

       

Row 3

       

Row 4

When n = 4, I = 2, j = 3, the output result is:

(2, 1) (2, 2) (2, 3) (2, 4) Position of the grid on the same row

(1, 3) (2, 3) (3, 3) (4, 3) Position of the grid in the same column

(1, 2) (2, 3) (3, 4) Position of the grid on the upper left to the lower right corner

() Position of the grid on the lower left to the upper right corner

 

Input
One row, three natural numbers N, I, j, and two adjacent numbers are separated by a single space. 1 <= N <= 10.
Output
Four rows:
First line: outputs the grid position of the same row from left to right;
Row 2: output the grid position of the same column from top to bottom;
Row 3: outputs the same diagonal grid position from top left to bottom right;
Row 4: output the grid position of the same diagonal line from bottom left to top right.

Each grid position is output in the following format: (x, y), x is the row number, y is the column number, and English Punctuation is used. There is no space in the middle.
Separate two adjacent grids with a single space.
Sample Input
4 2 3
Sample output
(2,1) (2,2) (2,3) (2,4)(1,3) (2,3) (3,3) (4,3)(1,2) (2,3) (3,4)(4,1) (3,2) (2,3) (1,4)
Source
Question 2 of NOIP1996 semi-finals popularity Group
 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 using namespace std; 6 int a[10001][10001]; 7 int b[10001][10001]; 8 int ans[10001][10001]; 9 int now;10 int tot;11 int main()12 {13     int n,x,y;14     cin>>n>>x>>y;15     for(int i=1;i<=n;i++)16     {17         for(int j=1;j<=n;j++)18         {19             if(i==x)20             cout<<"("<<i<<","<<j<<")"<<" ";21         }22     }23     cout<<endl;24     for(int i=1;i<=n;i++)25     {26         for(int j=1;j<=n;j++)27         {28             if(j==y)29             cout<<"("<<i<<","<<j<<")"<<" ";30         }31     }32     cout<<endl;33     for(int i=1;i<=n;i++)34     {35         for(int j=1;j<=n;j++)36         {37             if((j-i)==(y-x))38             cout<<"("<<i<<","<<j<<")"<<" ";39         }40     }41     cout<<endl;42     for(int i=n;i>=1;i--)43     {44         for(int j=n;j>=1;j--)45         {46             if((i+j)==(y+x))47             cout<<"("<<i<<","<<j<<")"<<" ";48         }49     }50     return 0;51 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.