[Swust OJ 234]--IrreducibleNumber(题意太坑)

时间:2023-08-12 17:42:43

题目链接:http://acm.swust.edu.cn/problem/0234/

Time limit(ms): 1000        Memory limit(kb): 65535
Description
You are given a list of number. An integer K is irreducible with respect to the numbers if K cannot be represented as 
a sum of one or more elements from the numbers, where each element of the numbers may be used at most once. Return 
the smallest positive integer that is irreducible with respect to the given numbers.
Input
n: the size of the numbers, -1 indicates end. (1 =< n <= 3) 
next line contains n numbers (1 =< number <= 100)
Output
the smallest positive integer that is irreducible with respect to the given numbers.
Sample Input
2
1 1
2
1 2
-1
Sample Output
3
4
SCPC__张剑
题目大意:题意是这样的,输入n(n!=-1),接下来n个数,凡是这些数和它们相加能得到的数字都不能使用,从1开始遍历,把能使用的最小的数输出来~~~
代码如下:
由于最多3个数
 #include <iostream>
using namespace std;
int a[], vis[];
int main(){
int n, i;
while (cin >> n, n != -){
memset(vis, , sizeof(vis));
for (i = ; i <= n; i++){
cin >> a[i];
vis[a[i]] = ;
}
if (n == ){
vis[a[] + a[]] = ;
}
else{
vis[a[] + a[]] = ;
vis[a[] + a[]] = ;
vis[a[] + a[]] = ;
vis[a[] + a[] + a[]] = ;
}
for (i = ;; i++)
if (!vis[i]) {
cout << i << endl;
break;
}
}
return ;
}

其实多简单的,就是题意太坑了有木有~~~