# yzoj 2372 小B的数字 题解

### 样例输入

3
2
3 2
3
3 3 3
2
1 10

### 样例输出

YES
YES
NO

### 解析

$lcm* sum \geq sum * ( \sum_{i = 1}^{n} {\frac{lcm}{a_i}} )$

#### 方法一（不推荐

#include<bits/stdc++.h>
using namespace std;
const double eps=1e-6;
int T,n,k;
bool cheak(double a,double b){
if(a-b<=eps) return true;
else return false;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);
double sum=0;
for(int i=1;i<=n;++i){
scanf("%d",&k);
sum+=1.0/(double)k;
}
if(cheak(sum,(double)1)) printf("YES\n");
else printf("NO\n");
}
return 0;
}

#### 方法二(正解

$( \sum_{i = 1}^{n} {\frac{10!}{a_i}} \leq 10!)$

#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
typedef long long ll;
int main(){
int t;
scanf("%d",&t);
while (t--){
int n;
scanf("%d",&n);
ll tot=0;
for(int i=0;i<n;i++){
int x;
scanf("%d",&x);
tot+=3628800/x;
}
puts(tot<=3628800 ? "YES" : "NO");
}
return 0;
}

#### 方法三(巧妙的暴力

#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
scanf("%d",&t);
while (t--){
int n;bool flag=1;
scanf("%d",&n);
long long tot=0;
long long pop=1;
int maxn=0;
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
maxn=max(maxn,x);
if(x==1) flag=0;
tot+=x;
pop*=x;
}
if(!flag || n>maxn) printf("NO\n");
else puts(tot<=pop ? "YES" : "NO");
}
return 0;
}
posted @ 2019-10-12 20:03  End_donkey  阅读(...)  评论(...编辑  收藏