codeforces 441C. Valera and Tubes 解题报告
题目链接: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 解题报告的更多相关文章
- Codeforces 441C Valera and Tubes
题目链接:Codeforces 441C Valera and Tubes 没看到r >= 2一直错.让前几个管子占用2个格子.最后一个把剩下的都占用了.假设问题有解.这样做一定有解.其它策略就 ...
- codeforces 441B. Valera and Fruits 解题报告
题目链接:http://codeforces.com/problemset/problem/441/B 题目意思:有 n 棵fruit trees,每课水果树有两个参数描述:水果成熟的时间和这棵树上水 ...
- codeforces B. Valera and Contest 解题报告
题目链接:http://codeforces.com/problemset/problem/369/B 题目意思:给出6个整数, n, k, l, r, sall, sk ,需要找出一个满足下列条件的 ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- codeforces 476C.Dreamoon and Sums 解题报告
题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- codeforces 507B. Amr and Pins 解题报告
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- codeforces B. Xenia and Ringroad 解题报告
题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...
随机推荐
- codeforces Gym 101572 I 有向图最小环路径
题目链接 http://codeforces.com/gym/101572 题意 一共n个文件 存在依赖关系 根据给出的依赖关系 判断是否存在循环依赖 ,不存在的话输出SHIP IT,存在的话 ...
- luogu P1342 请柬
题目描述 在电视时代,没有多少人观看戏剧表演.Malidinesia古董喜剧演员意识到这一事实,他们想宣传剧院,尤其是古色古香的喜剧片.他们已经打印请帖和所有必要的信息和计划.许多学生被雇来分发这些请 ...
- Atcoder 2373 Cookie Exchanges
Problem Statement Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively ...
- 精通python网络爬虫之自动爬取网页的爬虫 代码记录
items的编写 # -*- coding: utf-8 -*- # Define here the models for your scraped items # # See documentati ...
- Java并发编程关键字synchronized的总结
一.对synchronized的了解 synchronized关键字解决的是多个线程之间访问资源的同步性,synchronized关键字可以保证被它修饰的方法或者代码块在任意时刻只能有一个线程执行. ...
- Java并发编程实战 读书笔记(二)
关于发布和逸出 并发编程实践中,this引用逃逸("this"escape)是指对象还没有构造完成,它的this引用就被发布出去了.这是危及到线程安全的,因为其他线程有可能通过这个 ...
- VS2015 当前不会命中断点,还没有为该文档加载任何符号
这种小问题,我想只需要清理解决方案重新生成就好啦,结果...2个小时过去后.. 最后问了昨天做过修改的同事,修改了什么.. 设置成生成调试信息,仅以此文纪念我那逝去的青春
- Web常见安全漏洞原理及防范-学习笔记
公司在i春秋上面报的一个课程.http://www.ichunqiu.com/course/55885,视频学习. OWASP (Open Web Application Secutiry Proje ...
- 【Leetcode】经典的Jump Game in JAVA
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- POJ 3414:Pots
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11661 Accepted: 4940 Special J ...