[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
Sample Output
SCPC__张剑
题目大意:题意是这样的,输入n(n!=-1),接下来n个数,凡是这些数和它们相加能得到的数字都不能使用,从1开始遍历,把能使用的最小的数输出来~~~
代码如下:
由于最多3个数
View Code
其实多简单的,就是题意太坑了有木有~~~
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 |
3 4 |
题目大意:题意是这样的,输入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
其实多简单的,就是题意太坑了有木有~~~
相关文章推荐
- 记录学习MVC过程,MVC验证(四)
- 怎样保证客户端和服务器端数据的一致性(数据的同步)
- B/S结构 & C/S结构
- [LeetCode]House Robber II
- Mybatis开发dao两种方法
- java俄罗斯方块
- mfc笔记(一)
- Divide Two Integers
- jdk及tomcat(免安装版)系统配置
- java中的数字格式化
- vim开发配置,函数颜色格式设置
- 函数输出多个返回值
- 【Unity3D】生成工程报错解决—UnityEditor.HostView:OnGUI() Error building Player: Couldn't build player because of unsupported data on target platform.
- caj格式如何转成pdf格式
- Html语义化的理解
- Android事件分发机制完全解析,带你从源码的角度彻底理解(下)
- BeautifulSoup下载给定URL里的图片(一)
- 2015.06.15,学习,读书笔记-《语法俱乐部》学习笔记
- Web系统页面打印技术实现与分析
- Memcache(MC)系列(七)Memcache stats命令