首页 > 其他分享 >POJ 3970 Party

POJ 3970 Party

时间:2022-11-09 19:31:16浏览次数:37  
标签:int money CEO 3970 POJ ans Party include define


Description



The CEO of ACM (Association of Cryptographic Mavericks) organization has invited all of his teams to the annual all-hands meeting, being a very disciplined person, the CEO decided to give a money award to the first team that shows up to the meeting. 

The CEO knows the number of employees in each of his teams and wants to determine X the least amount of money he should bring so that he awards the first team to show up such that all team members receive the same amount of money. You must write a program to help the CEO achieve this task.


Input



The input consists of multiple test cases, each test case is described on a line by itself, Each line starts with an integer N (1 <= N <= 20) the number of teams in the organization followed by N space separated positive integers representing the number of employees in each of the N teams. You may assume that X will always fit in a 32 bit signed integer. The last line of input starts with 0 and shouldn't be processed.


Output



For each test case in the input print "The CEO must bring X pounds.", where X is as described above or "Too much money to pay!" if X is 1000000 or more. 


Sample Input



1 3000000 2 12 4 0


Sample Output



Too much money to pay!

The CEO must bring 12 pounds.


就是求个最大公倍数,注意判断超出的情况。

#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define fi first
#define se second
#define mp(i,j) make_pair(i,j)
#define pii pair<int,int>
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-4;
const int INF = 0x7FFFFFFF;
const int mod = 9973;
const int N = 3e5 + 10;
int n, x;

LL gcd(LL x, LL y)
{
return x%y ? gcd(y, x%y) : y;
}

int main()
{
while (scanf("%d", &n), n)
{
LL ans = 1;
while (n--)
{
scanf("%d", &x);
if (ans == -1) continue;
if (x >= 1000000) { ans = -1; continue; }
ans = ans / gcd(ans, x) * x;
if (ans >= 1000000) ans = -1;
}
if (ans == -1) puts("Too much money to pay!");
else printf("The CEO must bring %lld pounds.\n", ans);
}
return 0;
}



标签:int,money,CEO,3970,POJ,ans,Party,include,define
From: https://blog.51cto.com/u_15870896/5838625

相关文章

  • SPOJ LCS Longest Common Substring
    DescriptionAstringisfinitesequenceofcharactersoveranon-emptyfinitesetΣ.Inthisproblem,Σisthesetoflowercaseletters.Substring,alsocalled......
  • SPOJ LCS2 Longest Common Substring II
    DescriptionAstringisfinitesequenceofcharactersoveranon-emptyfinitesetΣ.Inthisproblem,Σisthesetoflowercaseletters.Substring,alsocalled......
  • POJ 3458 Colour Sequence
    DescriptionWehaveapileofcardsconsistingof100cardsthatarecolouredonbothsides.Thereisafinitenumberofcolours(atmost26).Inadditionthe......
  • SPOJ 705 New Distinct Substrings
    DescriptionGivenastring,weneedtofindthetotalnumberofitsdistinctsubstrings.InputT-numberoftestcases.T<=20;Eachtestcaseconsistsofonestr......
  • POJ 1743 Musical Theme
    DescriptionAmusicalmelodyisrepresentedasasequenceofN(1<=N<=20000)notesthatareintegersintherange1..88,eachrepresentingakeyonthepi......
  • 究竟什么是POJO?
    POJO(PlainOldJavaObject)这种叫法是MartinFowler、RebeccaParsons和JoshMacKenzie在2000年的一次演讲的时候提出来的。     我在做J2EE培训中发现我的......
  • POJ3061 Subsequence
    思路:尺取法注意本题目中所有的内容全部是证书,这就为我们维护了一个很好的单调性.考虑最暴力的\(\mathcalO(n^3)\)的做法,就是枚举起点,终点,然后分别求和.但是......
  • POJ-1018
    POJ-1018(现在好像过不了)题意目前有一个公司需要购进宽带设备,每种设备有多款机器供选择,每种设备都需购进一台,现给出每台设备的带宽p与价格q,要求选择设备的最小带宽\(min(......
  • POJ-3737
    POJ-3737题意给出一个圆锥的表面积,求最大体积。思路显然,得到底面积的半径后,一切都能得到。在我们慢慢延长半径时,发现不满足线性,而是单峰函数。故三分。圆锥复习Code......
  • poj 2392 Space Elevator
    给出了一些砖块,砖块有高度,最高可以达到的高度(高度限制)和数量,问可以用这些砖块堆的最大高度   f[i][j]考虑前i块,能否堆出高度为j   f[i][j]|=f[i-1][j-k*h[i]......