Codeforces 441C Valera and Tubes

题目链接:Codeforces 441C Valera and Tubes

没看到r >= 2一直错。让前几个管子占用2个格子。最后一个把剩下的都占用了。假设问题有解。这样做一定有解。其它策略就不一定了(比方让某个管子占用了3个格子。而总共同拥有四个格子,两个管子)。

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int x = 1, y = 1;
    bool flag = false;
    for(int i = 0; i < k - 1; i++)
    {
        printf("2");
        for(int j = 0; j < 2; j++)
        {
            if(!flag)
                printf(" %d %d", x, y++);
            else
                printf(" %d %d", x, y--);
            if(y > m)
            {
                flag = !flag;
                x++;
                y = m;
            }
            if(y < 1)
            {
                flag = !flag;
                x++;
                y = 1;
            }
        }
        puts("");
    }
    printf("%d", n * m - ((k - 1) * 2));
    while(x <= n)
    {
        if(!flag)
            printf(" %d %d", x, y++);
        else
            printf(" %d %d", x, y--);
        if(y > m)
        {
            flag = !flag;
            x++;
            y = m;
        }
        if(y < 1)
        {
            flag = !flag;
            x++;
            y = 1;
        }
    }
    puts("");
    return 0;
}
时间: 2024-08-05 11:48:53

Codeforces 441C Valera and Tubes的相关文章

Codeforces A. Valera and X 题解

判断二维字符串是否满足下面条件: on both diagonals of the square paper all letters are the same; all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the progra

codeforces A. Valera and Plates 题解

Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl.

codeforces Round #252 (Div. 2) C - Valera and Tubes

贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #include <algorithm> #include <utility> using namespace std; typedef pair<int,int> Point; int main(){ int n, m, k, flag = -1; cin >>

CodeForces - 369C - Valera and Elections

369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int N=1e5+5; vector<int>g[N]; vector<int>edge[N]; vector<int&

Codeforces 441D Valera and Swaps(置换群)

题意: 给定一个1~n的排列(n<=3000),输出字典序最小且次数最少的交换操作,使得操作后的排列可以通过最少m次交换得到排列[1,2,...n] Solution: 可以将排列的对应关系看做边,f[i]=i,代表自环.那么根据置换原理,图中有k个环,则需要最少n-k次交换操作得到排列[1,2...n].所以,先找出图中的环,对同一个环的位置进行标记.这样对不在同一个环的两个位置进行交换,会将两个环合并.将在同一个环内的两个位置进行交换,会将这个环分成两个环. 只需要,判断需要加环还是去环.贪

CodeForces 369A Valera and Plates( 水)

#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int bowl,plate; int n; int dish[1100]; int main() { int i,j; while(scanf("%d%d%d",&n,&bowl,&plate)!=EOF) { int ans

Codeforces 369E Valera and Queries --树状数组+离线操作

题意:给一些线段,然后给m个查询,每次查询都给出一些点,问有多少条线段包含这个点集中的一个或多个点 解法:直接离线以点为基准和以线段为基准都不好处理,“正难则反”,我们试着求有多少线段是不包含某个查询的任意一个点的.这时候我们可以建立点集的补集,以线段的形式,如果点集的补集线段包含了某条给出的线段,那么被包含的那条线段肯定不会包括任意一个点,那么该组查询的答案ans--即可. 用树状数组做,离线读入数据,按容易被包含的线段优先排个序,然后扫一遍,边统计边修改即可. 代码: #include <i

Codeforces Round #252 (Div. 2)

A. Valera and Antique Items 题目大意:有一场拍卖,有n个卖家,每个卖家有ki个物品并且底价知道,你想买东西并且只有V元钱,问可以从哪几个商家那里去买 思路:对每个卖家的每样商品作比较即可 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #define maxn 1000 5 using namespace std; 6 int ans[maxn],h,x,k; 7

Codeforces441C_Valera and Tubes(暴力)

Valera and Tubes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Valera has got a rectangle table consisting of?n?rows and?m?columns. Valera numbered the table rows starting from one, from