Educational Codeforces Round 108 (Rated for Div. 2)-B. The Cake Is a Lie-题解

Posted Tisfy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 108 (Rated for Div. 2)-B. The Cake Is a Lie-题解相关的知识,希望对你有一定的参考价值。

Educational Codeforces Round 108 (Rated for Div. 2)-B. The Cake Is a Lie

传送门
Time Limit: 2 seconds
Memory Limit: 256 megabytes

Problem Description

There is a n × m n \\times m n×m grid. You are standing at cell ( 1 , 1 ) (1, 1) (1,1) and your goal is to finish at cell ( n , m ) (n, m) (n,m).

You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell ( x , y ) (x, y) (x,y). You can:

Can you reach cell ( n , m ) (n, m) (n,m) spending exactly k k k burles?

Input

The first line contains the single integer t t t ( 1 ≤ t ≤ 100 1 \\le t \\le 100 1t100) — the number of test cases.

The first and only line of each test case contains three integers n n n, m m m, and k k k ( 1 ≤ n , m ≤ 100 1 \\le n, m \\le 100 1n,m100; 0 ≤ k ≤ 1 0 4 0 \\le k \\le 10^4 0k104) — the sizes of grid and the exact amount of money you need to spend.

Output

For each test case, if you can reach cell ( n , m ) (n, m) (n,m) spending exactly k k k burles, print YES. Otherwise, print NO.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

Sample Input

6
1 1 0
2 2 2
2 2 3
2 2 4
1 4 3
100 100 10000

Sample Onput

YES
NO
YES
NO
YES
NO

Note

In the first test case, you are already in the final cell, so you spend 0 0 0 burles.

In the second, third and fourth test cases, there are two paths from ( 1 , 1 ) (1, 1) (1,1) to ( 2 , 2 ) (2, 2) (2,2): ( 1 , 1 ) (1, 1) (1,1) → \\rightarrow ( 1 , 2 ) (1, 2) (1,2) → \\rightarrow ( 2 , 2 ) (2, 2) (2,2) or ( 1 , 1 ) (1, 1) (1,1) → \\rightarrow ( 2 , 1 ) (2, 1) (2,1) → \\rightarrow ( 2 , 2 ) (2, 2) (2,2). Both costs 1 + 2 = 3 1 + 2 = 3 1+2=3 burles, so it’s the only amount of money you can spend.

In the fifth test case, there is the only way from ( 1 , 1 ) (1, 1) (1,1) to ( 1 , 4 ) (1, 4) (1,4) and it costs 1 + 1 + 1 = 3 1 + 1 + 1 = 3 1+1+1=3 burles.


题目大意

在一个二维坐标平面,从点 ( 1 , 1 ) (1,1) (1,1)出发到点 ( n , m ) (n,m) (n,m)
其中在点 ( x , y ) (x,y) (x,y)只能花费 y ¥ y¥ y x + 1 x+1 x+1,或者花费 x ¥ x¥ x y + 1 y+1 y+1
问能不能花费 k ¥ k¥ k到达。


解题思路

其实不难发现,先在 x x x方向走动与先在 y y y方向走动,最终到达点 ( n , m ) (n,m) (n,m)所花费的 ¥ ¥ 是一样的。所以只需要先全部往 y y y方向走,到点 ( n , 1 ) (n,1) (n,1)后往 x x x方向走,直到到达点 ( n , m ) (n,m) (n,m),看花费是否正好等于 k k k即可。


AC代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
        int n,m,k;
        cin>>n>>m>>k;
        int s=0;
        for(int i=1;i<n;i++)
            s+=1;
        for(int j=1;j<m;j++)
            s+=n;
        puts(s==k?"YES":"NO");
    }
    return 0;
}

原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/116330973

以上是关于Educational Codeforces Round 108 (Rated for Div. 2)-B. The Cake Is a Lie-题解的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27