Codeforces Round 1519 B The Cake Is a Lie

题目描述

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;
}

                                                                仅供参考,请多指教

Codeforces Round 887是一个程序设计竞赛活动,由Codeforces组织举办。根据引用中的代码,该竞赛的题目要求解决一个序列操作的问题。给定一个长度为n的序列,通过执行一系列操作,使得序列变得非sorted,即非严格递增。具体操作是将序列中[1, i]范围内的数字全部加一,同时将[i+1, n]范围内的数字全部减一。问题要求求解最少需要执行多少次操作才能达到要求。 引用中的代码给出了解决这个问题的实现。代码首先读入序列的长度n和序列a。然后通过判断序列是否已经是非sorted,如果是则直接输出0。接下来,代码遍历序列,求出相邻两个数字的差的最小值。最后,计算出最少需要执行的操作次数,并输出结果。 需要注意的是,引用中的代码只是给出了解决问题的一种实现方式,并不代表Codeforces Round 887的具体题目和解答。要了解该竞赛的具体信息,需要参考Codeforces官方网站或相关资料。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Codeforces Round 887 (Div. 2)](https://blog.csdn.net/qq_36545889/article/details/131905067)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值