Question link: http://codeforces.com/contest/441/problem/C
Tips: There is an n*m matrix, and you need to fill it with k pipes For rectangular shapes, pipes can only be placed horizontally or vertically, not diagonally. Allows you to output the coordinates of the passing points of the pipeline for each line. Because there are many placement methods, you only need to output any one that meets the conditions.
Since n,?m,?k (2?≤?n,?m?≤?300; 2?≤?2k?≤?n·m), the first k-1 pipes only need It occupies two points and the last pipe has a serpentine trajectory, so that all situations are satisfied.
#include <iostream>#include <cstdio>#define MAX_N 300using namespace std;int main(){ #ifndef ONLINE_JUDGE freopen("D:/out.txt","w",stdout); #endif //ONLINE_JUDGE int n,m,k; scanf("%d%d%d",&n,&m,&k); int i=1; int j=1; bool s=true; for(int p=1;p<k;p++) { printf("2"); for(int t=1;t<=2;t++) { if(!s&&t==2&&j==1) { printf(" %d %d",i++,j); s=true; } else if(s&&t==2&&j==m) { printf(" %d %d",i++,j); s=false; } else if(s&&t==1&&j==m) { printf(" %d %d",i++,j); s=false; } else if(s) { printf(" %d %d",i,j); j++; } else { printf(" %d %d",i,j); j--; } } printf("\n"); } printf("%d ",n*m-(k-1)*2); for(;i<=n;i+=2) { if(s) { for(;j<=m;j++) printf("%d %d ",i,j); j--; if(i<n) { for(;j>=1;j--) printf("%d %d ",i+1,j); } j++; } else { for(;j>=1;j--) { printf("%d %d ",i,j); } j++; if(i<n) { for(;j<=m;j++) printf("%d %d ",i+1,j); } j--; } } return 0;}