题目描述
There is a n×mn×m grid. You are standing at cell (1,1)(1,1) and your goal is to finish at cell (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). You can:
- move right to the cell (x,y+1)(x,y+1) — it costs x burles;
- move down to the cell (x+1,y)(x+1,y) — it costs y burles.
Can you reach cell (n,m)(n,m) spending exactly k burles?
输入
The first line contains the single integer t (1≤t≤100) — the number of test cases.
The first and only line of each test case contains three integers nn, mm, and k (1≤n,m≤1001≤n,m≤100; 0≤k≤10^4) — the sizes of grid and the exact amount of money you need to spend.
输出
For each test case, if you can reach cell (n,m)(n,m) spending exactly 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).
样例
输入 :
6
1 1 0
2 2 2
2 2 3
2 2 4
1 4 3
100 100 10000
输出 :
YES
NO
YES
NO
YES
NO
思路分析
此题如果要追求速度,就要找规律:((m-1)*1+(n-1)*m)==s.
#include <iostream>
using namespace std;
int main () {
int n,m,s;
int a;
cin>>a;
string b[a];
for (int i=0;i<a;i++){
cin>>n>>m>>s;
if (((m-1)*1+(n-1)*m)==s){
b[i]="YES";
}
else
b[i]="NO";
}
for (int i=0;i<a;i++){
cout<<b[i]<<endl;
}
return 0;
}
仅供参考,请多指教