Educational Codeforces Round 35 (Rated for Div. 2) C. Three Garlands(思维)(打表)

Three Garlands:

题目大意:(文末有原题)

有三盏灯,给出三个亮灯间隔:a, b, c;亮灯规则是 i(开灯时间)、i+x(亮灯间隔)、i+2*x、...,在三盏灯都打开之后,如果能保证每一秒都有灯在亮,则输出“YES”,否则输出“NO”;

思路:(应该也算是打表吧)

因为只有三盏灯,所以最大的亮灯间隔是3,且必须要保证三个灯的亮灯间隔都是3;

并且如果有一盏灯亮灯间隔是1(每秒都亮),则一定是可以的;

剩下的就是两盏灯时候,经过验证可以知道,只有满足 2、2、x(任意数)或者 4、4、2才能保证每秒都有灯亮(eg:

4 :2 6 10 14 18

4: 4 8 12 16 20

2: 3 5 7 9 11 13 15 17 19 21 

)(因为2比较特殊,所以就来试一下,就发现了)

其余都情况都不能满足;(可以验证几个,比如6 6 3, 6 3 3,...)

代码:

#include <iostream>
using namespace std;

int s[10];
int a, b, c;

void sum(int x) {      //求有几个x;
	s[x] = 0;
	if(a == x) s[x]++;
	if(b == x) s[x]++;
	if(c == x) s[x]++;
}

int main() {
	cin >> a >> b >> c;
	
	if(a == 1 || b == 1 || c == 1) {
		cout << "YES" << endl;
	}else {
		sum(2);
		sum(3);
		sum(4);
		
		if(s[3] == 3) cout << "YES" << endl;
		else if(s[2] >= 2) cout << "YES" << endl;
		else if(s[4] == 2 && s[2] == 1) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

原题:

题目:

Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.

When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if i-th garland is switched on during x-th second, then it is lit only during seconds x, x + ki, x + 2ki, x + 3ki and so on.

Mishka wants to switch on the garlands in such a way that during each second after switching the garlands on there would be at least one lit garland. Formally, Mishka wants to choose three integers x1, x2 and x3 (not necessarily distinct) so that he will switch on the first garland during x1-th second, the second one — during x2-th second, and the third one — during x3-th second, respectively, and during each second starting from max(x1, x2, x3) at least one garland will be lit.

Help Mishka by telling him if it is possible to do this!InputOutput

输入:

The first line contains three integers k1, k2 and k3 (1 ≤ ki ≤ 1500) — time intervals of the garlands.

输出:

If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.

Otherwise, print NO.

样例:

Input:

2 2 3

Output:

YES

Input:

4 2 3

Output:

NO

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值