首页 > 编程语言 > 详细

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

时间:2015-06-16 22:40:04      阅读:311      评论:0      收藏:0      [点我收藏+]

 

题目链接: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个数
技术分享
 1 #include <iostream>
 2 using namespace std;
 3 int a[5], vis[301];
 4 int main(){
 5     int n, i;
 6     while (cin >> n, n != -1){
 7         memset(vis, 0, sizeof(vis));
 8         for (i = 1; i <= n; i++){
 9             cin >> a[i];
10             vis[a[i]] = 1;
11         }
12         if (n == 2){
13             vis[a[1] + a[2]] = 1;
14         }
15         else{
16             vis[a[1] + a[2]] = 1;
17             vis[a[2] + a[3]] = 1;
18             vis[a[1] + a[3]] = 1;
19             vis[a[1] + a[2] + a[3]] = 1;
20         }
21         for (i = 1;; i++)
22         if (!vis[i]) {
23             cout << i << endl;
24             break;
25         }
26     }
27     return 0;
28 }
View Code

 

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

 

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

原文:http://www.cnblogs.com/zyxStar/p/4581827.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!