Description:
n * m 的地图,建设k个管道管道只能横竖走,且长度大于等于2,问你任意一种建设方法
Solution:
图里没有障碍,所以先把前k - 1个管道每个分2个长度,最后一个管道一连到底
Code:
PS:今天时间没来的急,其实函数可以封装一下的,虽然都是暴力,但也得暴力的优美不是??
#include <iostream> #include <cstdio> using namespace std; int main() { int n,m,k; while(~scanf("%d%d%d",&n,&m,&k)) { int all = n * m; int num = 0; int i = 1; int x = 1; int y = 1; while(x <= n && y <= m) { while(y <= m) { if(i < k && num == 0) { printf("%d %d %d",2,x,y); ++num; } else if(i < k && num == 1) { printf(" %d %d\n",x,y); num = 0; ++i; } else if(i == k) { ++i; printf("%d %d %d",all - k * 2 + 2,x,y); } else if(i > k) { printf(" %d %d",x,y); } y++; } y--; x++; if(x > n)break; while(y >= 1) { if(i < k && num == 0) { printf("%d %d %d",2,x,y); ++num; } else if(i < k && num == 1) { printf(" %d %d\n",x,y); num = 0; ++i; } else if(i == k) { ++i; printf("%d %d %d",all - k * 2 + 2,x,y); } else if(i > k) { printf(" %d %d",x,y); } y--; } y++;x++; } printf("\n"); } return 0; }
原文地址:https://www.cnblogs.com/DF-yimeng/p/9630697.html
时间: 2024-10-08 22:11:56