您的位置:首页 > 其它

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

2015-06-16 21:20 260 查看
题目链接: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[5], vis[301];
int main(){
int n, i;
while (cin >> n, n != -1){
memset(vis, 0, sizeof(vis));
for (i = 1; i <= n; i++){
cin >> a[i];
vis[a[i]] = 1;
}
if (n == 2){
vis[a[1] + a[2]] = 1;
}
else{
vis[a[1] + a[2]] = 1;
vis[a[2] + a[3]] = 1;
vis[a[1] + a[3]] = 1;
vis[a[1] + a[2] + a[3]] = 1;
}
for (i = 1;; i++)
if (!vis[i]) {
cout << i << endl;
break;
}
}
return 0;
}


View Code

其实多简单的,就是题意太坑了有木有~~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: