4269: 买iphone
Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1913 Solved: 365
Description
自从上次仓鼠中了1000万彩票后,彻底变成了土豪了,一群人愿意认他做干爹,仓鼠决定送他的干儿子每人一部iphone。仓鼠今天带了一群人去买iphone,每个人身上都背着一个大背包,只有3种背包,分别能装a,b,c个iphone,仓鼠希望每个人都能用iphone装满自己的背包。仓鼠有n个干儿子,也就是要买n部手机,仓鼠带了k个人去买手机,问是否存在一种情况能让每个买iphone的人的背包都装满
Input
输入包含多组测试数据,每组一行,包含5个整数n, k, a, b, c
(1 <= n, k , a, b, c <= 10000)
abc可以相同
Output
如果存在输出Yes,否则输出No
Sample Input
10 3 3 3 4 20 7 1 1 1 80 3 100 3 3 15 4 3 5 6
Sample Output
Yes No No Yes
HINT
样例一3个人分别带大小为 3 3 4的背包去买手机正好每个人都装满
样例二 很明显只有一种背包,全部都是1也无法买20部iphone
样例四 4个人分别带大小为 3 3 3 6的背包去买手机正好每个人都装满
Source
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <bitset>
#include <stack>
#include <map>
#include <climits>
#include <functional>
using namespace std;
#define LL long long
const int INF=0x3f3f3f3f;
int a[3],n,k;
int main()
{
while(~scanf("%d%d",&n,&k))
{
for(int i=0;i<3;i++) scanf("%d",&a[i]);
sort(a,a+3);
int flag=0;
for(int i=0;i<=k&&i*a[2]<=n;i++)
{
int x=n-i*a[2];
int y=k-i;
if(y*a[1]<x||y*a[0]>x) continue;
if(a[1]==a[0])
{
if(y*a[0]==x) {flag=1;break;}
else continue;
}
if((x-y*a[0])%(a[1]-a[0])==0)
{
flag=1;
break;
}
}
if(flag) printf("Yes\n");
else printf("No\n");
}
return 0;
}