题目链接:http://codeforces.com/problemset/problem/441/C

题目意思:将n * m 的矩阵分成 k 堆。每堆是由一些坐标点(x, y)组成的。每堆里面至少由 >= 2 个坐标点组成,这些坐标点还需要满足: |xi - xi + 1| + |yi - yi + 1| = 1 。这个等式表示遍历堆里面的坐标好像蛇形那样走,也就是坐标点与坐标点之间需要相邻!还有一个条件就是,每个坐标点只能用一次。

做了一整天= =。改了一个问题,另一个问题又出现了。终于被一个问题攻陷了= =。

整体思路就是 k - 1堆中,每堆由两个坐标组成,剩下的那一堆,由剩下未用的坐标构成。由于我做的时候是一竖竖地做的(假设 3 * 5的矩阵,1 1 1 2 2 1 2 2...),所以有个问题就是剩下的那堆,从第一行开始走的时候,是从左到右走还是从右到左走?我错误的代码中,判断不了对于分完k-1堆之后,箭头是如何走的!我是通过k-1堆之后被覆盖的总行数的奇偶数来判断的:奇数:从左至右,偶数:从右至左。但是对于行数为奇数来说,就不行了。以下这两种情况足以证实。

5  9  20

 (被覆盖的总行数为奇数,但正确走法应该是从右至左)

2   2  1

  (与推测相同)

先贴下我错的代码(读者可直接忽略),一场噩梦= =

(test 24 错了,说堆中有些tube 不符合条件)

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = + ;
int vis[maxn][maxn]; int main()
{
int n, m, k;
while (scanf("%d%d%d", &n, &m, &k) != EOF)
{
memset(vis, , sizeof(vis));
int row = , y = ;
int cnt, tmp, f = , sum = ;
for (cnt = ; cnt <= k-; )
{
if (y+ > m)
break;
printf("2 %d %d %d %d\n", row, y, row, y+);
vis[row][y] = vis[row][y+] = ;
sum += ;
row++;
cnt++;
if (!(row % n) && cnt+ <= k-)
{
printf("2 %d %d %d %d\n", row, y, row, y+);
vis[row][y] = vis[row][y+] = ;
sum += ;
y += ;
row = ;
f = ;
cnt++;
}
}
int col = m;
for (int row = ; row+ <= n && cnt <= k-; row += , cnt++)
{
printf("2 %d %d %d %d\n", row, col, row+, col);
vis[row][col] = vis[row+][col] = ;
sum += ;
}
tmp = (!f ? row- : n);
// printf("tmp = %d\n", tmp);
if ((n*m)-sum)
{
printf("%d ", n*m-sum);
int start = (tmp& ? : ); // 奇数顺着来走
for (int row = ; row <= n; row++)
{
if (start)
{
for (int col = ; col <= m; col++)
{
if (!vis[row][col])
printf("%d %d ", row, col);
}
}
else
{
for (int col = m; col >= ; col--)
{
if (!vis[row][col])
printf("%d %d ", row, col);
}
}
start ^= ;
}
}
printf("\n");
}
return ;
}

AC代码(真是简单就为美啊~~~)

规规矩矩,一行行顺着来做

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; int n, m, k; void next(int &x, int &y)
{
if (y == )
{
if (x & )
y++;
else
x++;
}
else if (y == m)
{
if (x & )
x++;
else
y--;
}
else if (x & )
y++;
else
y--;
} int main()
{
while (scanf("%d%d%d", &n, &m, &k) != EOF)
{
int x = , y = ;
int cnt = k;
while (cnt > )
{
printf("");
printf(" %d %d", x, y);
next(x, y);
printf(" %d %d\n", x, y);
next(x, y);
cnt--;
}
printf("%d", n*m-*(k-));
while (x >= && x <= n && y >= && y <= m)
{
printf(" %d %d", x, y);
next(x, y);
}
puts("");
}
return ;
}

codeforces 441C. Valera and Tubes 解题报告的更多相关文章

  1. Codeforces 441C Valera and Tubes

    题目链接:Codeforces 441C Valera and Tubes 没看到r >= 2一直错.让前几个管子占用2个格子.最后一个把剩下的都占用了.假设问题有解.这样做一定有解.其它策略就 ...

  2. codeforces 441B. Valera and Fruits 解题报告

    题目链接:http://codeforces.com/problemset/problem/441/B 题目意思:有 n 棵fruit trees,每课水果树有两个参数描述:水果成熟的时间和这棵树上水 ...

  3. codeforces B. Valera and Contest 解题报告

    题目链接:http://codeforces.com/problemset/problem/369/B 题目意思:给出6个整数, n, k, l, r, sall, sk ,需要找出一个满足下列条件的 ...

  4. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  5. codeforces 476C.Dreamoon and Sums 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...

  6. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  7. codeforces 507B. Amr and Pins 解题报告

    题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...

  8. codeforces 500B.New Year Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...

  9. codeforces B. Xenia and Ringroad 解题报告

    题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...

随机推荐

  1. 【SPOJ220】Relevant Phrases of Annihilation(后缀数组,二分)

    题意: n<=10,len<=1e4 思路: #include<cstdio> #include<cstring> #include<string> # ...

  2. eq=等于gt=大于lt=小于的英文全称

    EQ: Equal GT: Greater Than LT: Less than 知道全称就不会忘记

  3. 标准C程序设计七---02

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  4. 通过Nginx 的反向代理来加强kibana的访问安全

    https://blog.csdn.net/choelea/article/details/57406086

  5. MySQL的LOOP, LEAVE 和ITERATE语句(类似Continue、Break的写法)

    和REPEAT和while语句不同,LOOP.LEAVE.ITERATE更像其他编程语言中的goto语句. LOOP要设定一个label指定循环的开始位置,而LEAVE则像其他语言中的Break会离开 ...

  6. Centos7 下安装 RabbitMQ

    安装 erlang 1.下载erlang 官网地址 http://www.erlang.org/download 挑选合适的版本 然后 wget 比如目前最新版本 19.3 运行命令 wget htt ...

  7. Java集合——遍历集合元素并修改

    Java集合——遍历集合元素并修改 摘要:本文主要总结了遍历集合的方式,以及在遍历时修改集合要注意的问题. 遍历Collection 对List和Set的遍历,有四种方式,下面以ArrayList为例 ...

  8. MongoDB学习day10--数据库导入导出

    在 Mongodb 中我们使用 mongodump 命令来备份 MongoDB 数据. 该命令可以导出所有数据到指定目录中.mongodump 命令可以通过参数指定导出的数据量级转存的服务器. 使用m ...

  9. 洛谷 P3865 【模板】ST表

    P3865 [模板]ST表 题目背景 这是一道ST表经典题——静态区间最大值 请注意最大数据时限只有0.8s,数据强度不低,请务必保证你的每次查询复杂度为 O(1)O(1) 题目描述 给定一个长度为  ...

  10. 未能加载文件或程序集“System.EnterpriseServices, Version=4.0.0.0或2.0.0.0

    未能加载文件或程序集“System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50 ...