codeforces C. Valera and Tubes
http://codeforces.com/contest/441/problem/C
题意:有n×m个方格,然后把这些方格分成k部分,每个部分内的方格的坐标满足|xi - xi + 1| + |yi - yi + 1| = 1,且每一个部分内的方格数>=2,输出其中的一种方案。
思路:贪心,先让k-1部分,每一部分占2个方格,依次按照蛇形划分,剩余划分到最后一个内。
#include <cstdio>
#include <iostream>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#define maxn 1000100
#define ll long long
using namespace std; int n,m,k;
struct node
{
int x,y;
} st; int main()
{
cin>>n>>m>>k;
vector<node>g[];
int cnt=;
int x=;
for(int i=; i<=n; i++)
{
if(i%)
{
for(int j=; j<=m; j++)
{
cnt++;
st.x=i;
st.y=j;
g[x].push_back(st);
if(x<k-)
{
if(cnt%==)
{
x++;
}
}
}
}
else
{
for(int j=m; j>=; j--)
{
cnt++;
st.x=i;
st.y=j;
g[x].push_back(st);
if(x<k-)
{
if(cnt%==)
{
x++;
}
}
}
}
}
for(int i=; i<k; i++)
{
printf("%d ",(int)g[i].size());
for(int j=; j<(int)g[i].size(); j++)
{
st=g[i][j];
printf("%d %d ",st.x,st.y);
}
printf("\n");
}
return ;
}
codeforces C. Valera and Tubes的更多相关文章
- Codeforces 441C Valera and Tubes
题目链接:Codeforces 441C Valera and Tubes 没看到r >= 2一直错.让前几个管子占用2个格子.最后一个把剩下的都占用了.假设问题有解.这样做一定有解.其它策略就 ...
- codeforces 441C. Valera and Tubes 解题报告
题目链接:http://codeforces.com/problemset/problem/441/C 题目意思:将n * m 的矩阵分成 k 堆.每堆是由一些坐标点(x, y)组成的.每堆里面至少由 ...
- Valera and Tubes
C. Valera and Tubes time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForces - 369E Valera and Queries(树状数组)
CodeForces - 369E Valera and Queries 题目大意:给出n个线段(线段的左端点和右端点坐标)和m个查询,每个查询有cnt个点,要求给出有多少条线段包含至少其中一个点. ...
- codeforces Round #252 (Div. 2) C - Valera and Tubes
贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #i ...
- 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 - 441E:Valera and Number (DP&数学期望&二进制)
Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given belo ...
- CodeForces - 369C - Valera and Elections
369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/std ...
随机推荐
- linux下daemon守护进程的实现(以nginx代码为例)
ngx_int_t ngx_daemon(ngx_log_t *log) { int fd; // 让init进程成为新产生进程的父进程: // 调用fork函数创建子进程后,使父进程立即退出.这样, ...
- 全面分析 Spring 的编程式事务管理及声明式事务管理--转
开始之前 关于本教程 本教程将深入讲解 Spring 简单而强大的事务管理功能,包括编程式事务和声明式事务.通过对本教程的学习,您将能够理解 Spring 事务管理的本质,并灵活运用之. 先决条件 本 ...
- Linux命令行编辑快捷键
Linux命令行编辑快捷键: history 显示命令历史列表 ↑(Ctrl+p) 显示上一条命令 ↓(Ctrl+n) 显示下一条命令 !num 执行命令历史列表的第num条命令 !! 执行上一条命令 ...
- c读mysql产生乱码问题
在编写接口API时,发现中文字utf8输入的在linux下采用c读取显示为”??”问号,这是由于编码造成的. 很简单的两个地方做修改就搞定. 1.先找到mysql的my.cnf配置文件/etc/my. ...
- LayoutInflater类详解
http://www.cnblogs.com/top5/archive/2012/05/04/2482328.html 在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于 ...
- oracle 报Ora-01008错误:oracle 并非所有变量都已绑定的原因.TO_number();动态执行select..into..语句时
1.sql_temp := 'UPDATE B38_back SET '||code||'=TO_NUMBER(nvl('||:NEW.BACAI||',0))+'||OnMonth || ' WHE ...
- oracle备份表
oracle与sql单表备份的区别 ( oracle中备份表: create table 备份表名 as select * from 原表 sql server中备份表: select * i ...
- 用Ueditor存入数据库带HTML标签的文本,从数据库取出来后,anjular用ng-bind-html处理带HTML标签的文本
ng.module('index-filters', []) .filter('trustHtml', function ($sce) { return function (input) { retu ...
- Spring+AOP+Log4j 用注解的方式记录指定某个方法的日志
一.spring aop execution表达式说明 在使用spring框架配置AOP的时候,不管是通过XML配置文件还是注解的方式都需要定义pointcut"切入点" 例如定义 ...
- 升级10.10 Yosemite 后,cocoapods 出现错误(解决方案)
RSMacBook-Pro:~ RS$ pod search jsonkit /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/li ...