2 条题解

  • 0
    @ 2025-6-27 18:36:54

    正面构造要输出的东西

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int n,i,j;
    	cin>>n>>i>>j;
    	//输出同一行的
    	for(int y=1;y<=n;y++)
    		cout<<"("<<i<<","<<y<<") "; 
    	cout<<"\n";
    	// 输出同一列的
    	for(int x=1;x<=n;x++)
    		cout<<"("<<x<<","<<j<<") "; 
    	cout<<"\n";
    	// 左上到右下对角线
    	int x,y;
    	x=i,y=j;
    	while(x-1>=1&&y-1>=1)
    	{
    		x--;
    		y--;
    	}
    	while(x<=n&&y<=n)
    	{
    		cout<<"("<<x<<","<<y<<") "; 
    		x++,y++;
    	}	 
    	cout<<"\n";
    	// 左下到右上对角线
    	x=i,y=j;
    	while(x+1<=n&&y-1>=1)
    	{
    		x++;
    		y--;
    	}
    	while(x>=1&&x<=n&&y>=1&&y<=n)
    	{
    		cout<<"("<<x<<","<<y<<") "; 
    		x--,y++;
    	}	 
    	cout<<"\n";
    
    
    	return 0;
    }
    
    
    • 0
      @ 2022-12-24 10:31:25

      枚举所有可能的位置,检查要不要输出

      #include<bits/stdc++.h>
      using namespace std;
      int main(){
      	int n, x, y;
      	cin>>n>>x>>y;
      	//(x,y)同一行
      	for(int i=1;i<=n;i++)//枚举行
      		for(int j=1;j<=n;j++)//枚举列
      		{
      			//第i行第j列
      			if(i==x)
      				cout<<"("<<i<<","<<j<<")"<<" "; 
      		} 
      	cout<<"\n"; 
      	//(x,y)同一列
      	for(int i=1;i<=n;i++)//枚举行
      		for(int j=1;j<=n;j++)//枚举列
      		{
      			//第i行第j列
      			if(j==y)
      				cout<<"("<<i<<","<<j<<")"<<" "; 
      		} 
      	cout<<"\n";
      	//(x,y)左上到右下斜线 
      	for(int i=1;i<=n;i++)//枚举行
      		for(int j=1;j<=n;j++)//枚举列
      		{
      			//第i行第j列
      			if(x-y==i-j)
      				cout<<"("<<i<<","<<j<<")"<<" "; 
      		} 
      	cout<<"\n";
      	//(x,y)左下到右上斜线
      	for(int i=n;i>=1;i--)//枚举行
      		for(int j=1;j<=n;j++)//枚举列
      		{
      			//第i行第j列
      			if(x+y==i+j)
      				cout<<"("<<i<<","<<j<<")"<<" "; 
      		} 
      	cout<<"\n";
      	return 0;
      }
      
      
      • 1

      信息

      ID
      340
      时间
      1000ms
      内存
      128MiB
      难度
      6
      标签
      (无)
      递交数
      228
      已通过
      73
      上传者