本文已参与「新人创作礼」活动,一起开启掘金创作之路。
@TOC
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 grid. You are standing at cell and your goal is to finish at cell .
You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell . You can:
Can you reach cell spending exactly burles?
Input
The first line contains the single integer () — the number of test cases.
The first and only line of each test case contains three integers , , and (; ) — the sizes of grid and the exact amount of money you need to spend.
Output
For each test case, if you can reach cell spending exactly 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 burles.
In the second, third and fourth test cases, there are two paths from to : or . Both costs burles, so it's the only amount of money you can spend.
In the fifth test case, there is the only way from to and it costs burles.
题目大意
在一个二维坐标平面,从点出发到点, 其中在点只能花费到,或者花费到, 问能不能花费到达。
解题思路
其实不难发现,先在方向走动与先在方向走动,最终到达点所花费的是一样的。所以只需要先全部往方向走,到点后往方向走,直到到达点,看花费是否正好等于即可。
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;
}
同步发文于我的CSDN,原创不易,转载请附上原文链接哦~
Tisfy:letmefly.blog.csdn.net/article/det…