top1编程
← 返回题目
题解

【基础】格子问题

1 条题解

  • 0
    @ 2026-7-28 22:10:20
    #include<bits/stdc++.h>
    using namespace std;
          int main(){
          int a[100][100];
    	  int n,x,y;
    	  cin>>n>>x>>y;
    	  for(int i=1;i<=n;i++){
    	  	for(int j=1;j<=n;j++){
    	  		if(i==x)cout<<"("<<i<<","<<j<<")";
    		  }
    	  }	
    	  cout<<endl;
    	  for(int i=1;i<=n;i++){
    	  	for(int j=1;j<=n;j++){
    	  		if(j==y)cout<<"("<<i<<","<<j<<")";
    		  }
    	  }	
    	  cout<<endl;
        for(int i=1;i<=n;i++){
    	  	for(int j=1;j<=n;j++){
    	  		if(i-j==x-y)cout<<"("<<i<<","<<j<<")";
    		  }
    	  }	
          	cout<<endl;
        for(int i=n;i>=1;i--){
    	  	for(int j=n;j>=1;j--){
    	  		if(i+j==x+y)cout<<"("<<i<<","<<j<<")";
    		  }
    	  }	
          return 0;	
    	  }
    
    • 1