zoukankan      html  css  js  c++  java
  • [Swust OJ 234]--IrreducibleNumber(题意太坑)

    题目链接: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

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

  • 相关阅读:
    【Linux】Apache服务配置
    【Linux】LAMP环境搭建(简易版)
    【Linux】网络应用
    【Linux】系统管理
    【Linux】Linux(一)Linux常用命令
    【php】PDO
    【php】COOKIE和SESSION
    【php】面向对象(五)
    【php】面向对象(四)
    【php】面向对象(三)
  • 原文地址:https://www.cnblogs.com/zyxStar/p/4581827.html
Copyright © 2011-2022 走看看