Currency System in Geraldion

题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=201542

题意:

输入一个数n,表示几种不同面值的纸币。输入那组纸币的面值,问不能组成的价值中最小的是多少,如果所有价值都可以组成,则输出-1.

案例:

Inpu

5

1 2 3 4 5

Outpu

-1

思路分析:           当有面值为1的纸币时,你就会发现可以用1组成任意价值的钱。所以在1存在时直接输出-1。        当没有面值为1的纸币时,任何面值都无法组成1.        所以直接判断是否有1.源代码如下:
 1 #include<iostream>
 2 #include<algorithm>
 3 #define max 1000
 4 using namespace std;
 5 int main()
 6 {
 7     int n;
 8     cin>>n;
 9     int a[max];
10     for(int i=0;i<n;i++)
11         cin>>a[i];
12     sort(a,a+n);
13     if(a[0]==1)
14         cout<<"-1"<<endl;
15     else
16         cout<<"1"<<endl;
17     return 0;
18 }

 
时间: 2024-07-30 20:31:37

Currency System in Geraldion的相关文章

【打CF,学算法——一星级】Codeforces Round #313 (Div. 2) A. Currency System in Geraldion

[CF简单介绍] 提交链接:http://codeforces.com/contest/560/problem/A 题面: A. Currency System in Geraldion time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A magic island Geraldion, where Gerald lives,

Currency System in Geraldion (Codeforces 560A)

A  Currency System in Geraldion Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem

Codeforces Round #313 A. Currency System in Geraldion

Description A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of mone

Codeforces Round #313 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/560 水笔场... A. Currency System in Geraldion time limit per test:2 seconds memory limit per test:256 megabytes A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several va

Codeforces Round #313 (Div. 2)

A. Currency System in Geraldion 刚开始以为是什么动态规划,直接在那里叫这可怎么办?后来又想到如果10里面的数可以拼出来,那么大的也可以拼出来了,于是这样写就过了.今天早上一看人家的代码,才发现如果一可以拼出来,那么其他都可以拼出来.所以只需要将输入的数排序,第一个是不是一考虑一下就可以了.自己思维还是不够. #include<bits/stdc++.h> using namespace std; int a[1024],dp[1000000+5]; int ma

Codeforces Round #313 (Div. 2) 解题报告

A. Currency System in Geraldion: 题意:有n中不同面额的纸币,问用这些纸币所不能加和到的值的最小值. 思路:显然假设这些纸币的最小钱为1的话,它就能够组成随意面额. 假设这些纸币的最小值大于1,那么它所不能组成的最小面额就是1.所以自学求最小值就可以. 我的代码: #include <set> #include <map> #include <cmath> #include <stack> #include <queue

Codeforces Round #313 (Div. 2)(A,B,C,D)

A题: 题目地址:Currency System in Geraldion 题意:给出n中货币的面值(每种货币有无数张),要求不能表示出的货币的最小值,若所有面值的都能表示,输出-1. 思路:水题,就是看看有没有面值为1的货币,如果有的话,所有面值的货币都可以通过1的累加得到,如果没有的话,最小的不能表示的就当然是1辣. #include <stdio.h> #include <math.h> #include <string.h> #include <stdli

chd校内选拔赛题目+题解

题目链接   A. Currency System in Geraldion 有1时,所有大于等于1的数都可由1组成.没有1时,最小不幸的数就是1. 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 using namespace std; 5 void solve(){ 6 int n,x; 7 scanf("%d",&n); 8 int flag = 0; 9

Aizu - 2305 Beautiful Currency (二分 + DFS遍历)

F. Beautiful Currency Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main Submit Status PID: 39422 Font Size:  +   - Beautiful Currency KM country has N kinds of coins and each co