Loading

CF765C Table Tennis Game 2 题解

Problem

Solution

注意到题目中的一句话 Note that the game consisted of several complete sets.,即每一局都是完整的一局,由此我们可以得出三种无解情况:

  1. Misha 的得分和 Vanya 的得分都小于 \(k\)
  2. Misha 的得分无法赢整数轮且 Vanya 的得分小于 \(k\)
  3. Vanya 的得分无法赢整数轮且 Misha 的得分小于 \(k\)

容易想到有解时答案即为 $\left \lfloor {a \div k + b \div k } \right \rfloor $。

Code

#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define FOR(i,a,b) for(int i=(a);i>=(b);i--)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

int k,A,B;
int main()
{
	IOS;
	cin>>k>>A>>B;
	if(A<k && B<k)return cout<<"-1",0;
	if(A%k!=0 && B<k)return cout<<"-1",0;
	if(B%k!=0 && A<k)return cout<<"-1",0;
	cout<<A/k+B/k;

	return 0;
}
posted @ 2024-08-13 21:46  ๑҉v  阅读(3)  评论(0)    收藏  举报