Codeforces Round #734 (Div. 3)-D1. Domino (easy version)-题解

110 阅读3分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

在这里插入代码片

@TOC

Codeforces Round #734 (Div. 3)-A. Polycarp and Coins

传送门 Time Limit: 1 second Memory Limit: 256 megabytes

Problem Description

Polycarp must pay exactly nn burles at the checkout. He has coins of two nominal values: 11 burle and 22 burles. Polycarp likes both kinds of coins equally. So he doesn't want to pay with more coins of one type than with the other.

Thus, Polycarp wants to minimize the difference between the count of coins of 11 burle and 22 burles being used. Help him by determining two non-negative integer values c1c_1 and c2c_2 which are the number of coins of 11 burle and 22 burles, respectively, so that the total value of that number of coins is exactly nn (i. e. c1+2c2=nc_1 + 2 \cdot c_2 = n), and the absolute value of the difference between c1c_1 and c2c_2 is as little as possible (i. e. you must minimize c1c2|c_1-c_2|).

Input

The first line contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases. Then tt test cases follow.

Each test case consists of one line. This line contains one integer nn (1n1091 \le n \le 10^9) — the number of burles to be paid by Polycarp.

Output

For each test case, output a separate line containing two integers c1c_1 and c2c_2 (c1,c20c_1, c_2 \ge 0) separated by a space where c1c_1 is the number of coins of 11 burle and c2c_2 is the number of coins of 22 burles. If there are multiple optimal solutions, print any one.

Sample Input

6
1000
30
1
32
1000000000
5

Sample Onput

334 333
10 10
1 0
10 11
333333334 333333333
1 2

Note

The answer for the first test case is "334 333". The sum of the nominal values of all coins is 3341+3332=1000334 \cdot 1 + 333 \cdot 2 = 1000, whereas 334333=1|334 - 333| = 1. One can't get the better value because if c1c2=0|c_1 - c_2| = 0, then c1=c2c_1 = c_2 and c11+c12=1000c_1 \cdot 1 + c_1 \cdot 2 = 1000, but then the value of c1c_1 isn't an integer.

The answer for the second test case is "10 10". The sum of the nominal values is 101+102=3010 \cdot 1 + 10 \cdot 2 = 30 and 1010=0|10 - 10| = 0, whereas there's no number having an absolute value less than 00.


题目大意

n×mn\times m的方格,和一些1×21\times 2的多米诺骨牌。 多米诺骨牌可以横着放也可以竖着放,问你能不能正好有kk个多米诺骨牌是横着放的。

解题思路

分情况讨论就行了。但是要考虑周全。

  • 首先如果方格是偶数行的:
    • 如果要放奇数个水平的多米诺骨牌:

      那么必定有某处的剩下的行数是奇数(总的偶数-水平的奇数),奇数就不能被2整除,就不能剩下的全部由竖着的来填充。所以直接输出NO

    • 但如果要放偶数个水平的多米诺骨牌:

      先考虑周全一些(不管k),这样如果是奇数行的话必定是偶数列,就能旋转90^。变成偶数行了。 那么我们就先尽量把最左边两列从上到下放满,然后第三四列从上到下...,看看最后一列有没有超出边界即可。

  • 但如果是奇数行的话: 其实可以直接行列翻转为偶数行来使用上述方法处理。但是如果上面考虑了k是小于mn2\frac{m*n}{2}的,上面判断就简单了,但是下面就要另加判断了。这里也介绍一下但看奇数行如何分类 如果是奇数行,我们就先把第一行用水平骨牌填满,然后就变成偶数行了
    • 如果水平骨牌数量很少,不能填满第一行,直接NO
    • 如果水平骨牌填满了第一行,剩下的就变成偶数行了,看剩下是奇数个水平骨牌(奇数个不能配对,NO)还是偶数个水平骨牌(偶数个可以配对,YES)

AC代码

#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
        int n,m,k;
        cin>>n>>m>>k;
        if(n%2==0)//偶数行
        {
            if(k%2)//奇数个水平
            {
                puts("NO");
            }
            else // 偶数个水平
            {
                int lie=k/n; // 能填几列
                lie += (k%n!=0); // 如果不能正好填满这一列,余下半列也算上。
                lie*=2; // 一列水平骨牌其实占了水平方向的2块
                if(lie>m) // 已经超出m列这个边界了
                {
                    puts("NO");
                }
                else // 没有超出
                {
                    puts("YES");
                }          
            }
        }
        else // 奇数行
        {
            int firstLineNum=m/2; // 填满第一行需要几个水平骨牌
            k-=firstLineNum; // 还剩下几个水平骨牌
            if(k<0) // 剩下数量小于0了(本来就不够)
            {
                puts("NO");
            }
            else // 水平骨牌还有余量
            {
                if(k%2) // 剩下奇数个水平骨牌
                {
                    puts("NO"); // 不能配对,总会有某一列剩下奇数个空余块,用竖直骨牌无法填满
                }
                else // 剩下偶数个水平骨牌
                {
                    puts("YES"); // 可以填满
                }                
            }            
        }        
    }
    return 0;
}

同步发文于我的CSDN,原创不易,转载请附上原文链接哦~
Tisfy:letmefly.blog.csdn.net/article/det…