题目链接:Codeforces 390D Inna and Sweet Matrix
题目大意:给出n,m和k,表示在n*m的空地上放k个糖果,每次从(1,1)的位置开始移动,要求步数最少,并给出路径,位置上如果放了糖果就不能再移动过。
题目大意:移动的步数为横坐标和纵坐标的和-1,选定位置后先移动x坐标,在移动y坐标这样就不会发生说前一个糖果将路径占用。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 10005;
struct state {
int x, y;
}p[N];
int n, m, k, c;
bool cmp(const state& a, const state& b) {
return a.x + a.y < b.x + b.y;
}
void init () {
c = 0;
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
p[c].x = i; p[c].y = j; c++;
}
}
sort (p, p + c, cmp);
}
void handle(int x, int y) {
for (int i = 1; i <= x; i++) printf("(%d,1) ", i);
for (int i = 2; i <= y; i++) printf("(%d,%d) ", x, i);
printf("\n");
}
void solve () {
int ans = 0;
for (int i = 0; i < k; i++)
ans += p[i].x + p[i].y - 1;
printf("%d\n", ans);
for (int i = k-1; i >= 0; i--) {
handle(p[i].x, p[i].y);
}
}
int main () {
init();
solve ();
return 0;
}
分享到:
相关推荐
Codeforces - 1131C. Birthday(贪心)题目链接题目给你n和n个数,要你重新排列n个数,使得这些数的相邻差值中最大的那个值最小。stat
暴枚最长桌脚的长度$l$,然后长度比$l$长的桌脚全部都要砍掉长度比$l$短的桌脚选择代价前$k$小的砍掉用线段树维护;示例程序 :typedef long l
Codeforces 1925D Good Trip 题解
题目大意:给出 n 个数字组成的序列,现在可以对数列进行多次操作,每次操作可以选择其中一段连续的数列,用其平均数替换原位置,换句话说,若原连续数列为 1 2 3,则可以替换为 2 2 2,问如何操作可以使得最后答案...
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
codeforces每日一题。 题意: 给出一个数组,让你挑选出能组成任意pair差值为2的幂的序列,并且使这个序列长度尽可能大。 思路: 针对于挑选出来的序列,任意pair对的差值为2的幂数。 假设有多个pair对,设dis(a,b)=2...
codeforces编程网站预测分数插件
Educational Codeforces Round 157D. XOR Construction
Codeforces 1105B - Zuhair and Strings 测试点37个(全)
【并查集】Codeforces 566D Restructuring Company题面在这里对于本题,只需要再维护一个并查集表示i所在联通块的最右位置因为相邻
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
Codeforces 149 D-Coloring Brackets,动态规划求解
Codeforces 185A - Plant 全测试点49个
题意: 给出 nnn 个点,n−1n-1n−1 条边,最多询问 n2\frac{n}{2}2n 次,每次询问 u,vu,vu,v,会给出 uvuvuv的最近公共祖先,求树的根。 ...操作就是一个删除叶子节点的过程。 AC代码: const int N = 1010;...
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
题目大意:给出一个由 n 个点组成的树,现在可以询问 n/2 次(向下取整)LCA,确定根节点是哪个节点 题目分析:因为最多只能求 n/2 次lca,每次需要两个节点作为参数,也就是说每个点我们至多遍历一遍,读完题后没什么...
Some of the Codeforces problems codes