当前位置:网站首页>[Blue Bridge Cup 2017 preliminary] buns make up
[Blue Bridge Cup 2017 preliminary] buns make up
2022-07-06 11:25:00 【%xiao Q】
subject
Title Description
Xiao Ming has breakfast in a bun shop almost every morning . This bun shop has N Grow steamer , Among them the first i The kind of steamer can put Ai A steamed bun
Each kind of steamer has a lot of steamers , It can be thought of as an infinite cage .
Whenever a customer wants to buy X A steamed bun , Uncle will choose some steamed buns , So that these cages happen to have X A steamed bun .
Let's say there are 3 Grow steamer , You can put 3、4 and 5 A steamed bun . When customers want to buy 11 A bun , Uncle will choose 2 Cage 3 One more 1 Cage 5 One of the ( It is also possible to elect 1 Cage 3 One more 2 Cage 4 One of the ).
Of course, sometimes uncle baozi can't figure out the quantity customers want to buy .
Let's say there are 3 Grow steamer , You can put 4、5 and 6 A steamed bun . And customers want to buy 7 A bun , Uncle can't make it out .
Xiao Ming wants to know how many kinds of numbers can't be found by Uncle baozi .
Input format
The first line contains an integer N.(1 <= N <= 100)
following N Each line contains an integer Ai.(1 <= Ai <= 100)
Output format
The output line contains an integer to represent the answer . If you can't figure out an infinite number , Output INF.
sample input Copy
2
4
5
sample output Copy
6
Data range and tips
For example , The uncountable number includes :1, 2, 3, 6, 7, 11.
analysis :
This problem needs to know a theorem , Euclidean theorem : For not completely 0 The integer of a,b So there must be integers x,y bring gcd(x,y) = a * x + b * y.
So we can assume that a * x + b * y = d, To make the equation solvable , that d % gcd(a, b) = 0 It is inevitable , If gcd(a,b) = 1, that d Can divide any number , That is to say a,b this 2 Any number can be divided by numbers ( But there can't be negative numbers in it , So there are some numbers that cannot be summed up ), On the contrary, we can't .
So the first step is to find the greatest common divisor of these numbers , If gcd = 1, Then how many numbers can't be summed up in the judgment , If gcd != 1, Then there must be countless kinds of numbers that can't be summed up , Direct output INF.
Reference code :
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <unordered_map>
#define LL long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define reps(i, a, b) for(int i = a; i < b; i++)
#define pre(i, a, b) for(int i = b; i >= a; i--)
using namespace std;
const int N = 10010, M = 110;
int f[N];
int a[N];
int main()
{
int n;
cin >> n;
int g = 0;
rep(i, 1, n)
{
cin >> a[i];
g = __gcd(g, a[i]);
}
if(g != 1)
{
puts("INF");
return 0;
}
rep(i, 1, n) f[a[i]] = 1;
rep(i, 1, n)
for(int j = 0; j + a[i]<= 10000; j++) // Here to 10000 It's a little metaphysical ( mathematics , No )
{
if(f[j]) f[j + a[i]] = 1;
}
int ans = 0;
rep(i, 1, 10000)
if(!f[i]) ans++;
cout << ans << endl;
return 0;
}
边栏推荐
- Solve the problem of installing failed building wheel for pilot
- [蓝桥杯2020初赛] 平面切分
- [蓝桥杯2017初赛]包子凑数
- 学习问题1:127.0.0.1拒绝了我们的访问
- Case analysis of data inconsistency caused by Pt OSC table change
- Number game
- 01 project demand analysis (ordering system)
- C语言读取BMP文件
- vs2019 使用向导生成一个MFC应用程序
- Django running error: error loading mysqldb module solution
猜你喜欢
Rhcsa certification exam exercise (configured on the first host)
[free setup] asp Net online course selection system design and Implementation (source code +lunwen)
图片上色项目 —— Deoldify
Machine learning notes week02 convolutional neural network
Did you forget to register or load this tag 报错解决方法
Introduction and use of automatic machine learning framework (flaml, H2O)
Learning question 1:127.0.0.1 refused our visit
AcWing 242. A simple integer problem (tree array + difference)
02 staff information management after the actual project
软件测试与质量学习笔记3--白盒测试
随机推荐
Double to int precision loss
01 project demand analysis (ordering system)
Attention apply personal understanding to images
Codeforces Round #771 (Div. 2)
JDBC原理
Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
Kept VRRP script, preemptive delay, VIP unicast details
图片上色项目 —— Deoldify
vs2019 第一个MFC应用程序
快来走进JVM吧
ES6 let and const commands
L2-004 这是二叉搜索树吗? (25 分)
[蓝桥杯2017初赛]方格分割
Why can't I use the @test annotation after introducing JUnit
Face recognition_ recognition
[蓝桥杯2017初赛]包子凑数
02-项目实战之后台员工信息管理
Principes JDBC
Learning question 1:127.0.0.1 refused our visit
[Blue Bridge Cup 2017 preliminary] grid division