优先队列+模拟-Fox and Number Game

codeforces-Fox and Number Game

题目地址:http://codeforces.com/contest/389/problem/A

Time Limit: 1000ms

Fox Ciel is playing a game with numbers now.

Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small
as possible.

Please help Ciel to find this minimal sum.

Input

The first line contains an integer n (2?≤?n?≤?100). Then the second line contains n integers: x1, x2, ..., xn (1?≤?xi?≤?100).

Output

Output a single integer — the required minimal sum.

Sample Input

3

2 4 6

5

45 12 27 30 18

4

1 1 2 2

2

1 2

Sample Output

6

15

4

2

大意:每个测试用例是一个数组。找出xi和xj,(xi>xj),做运算令xi=xi-xj。可以做若干组这样的运算,使得最后的数组和最小。输出此和。

分析:用优先队列,每次找出最大的和次大的,处理后再加入此队列。注意多个相同的xi这种情况!

优先队列+模拟-Fox and Number Game

时间: 2024-10-17 02:18:13

优先队列+模拟-Fox and Number Game的相关文章

HDU5437 Alisha’s Party(优先队列+模拟)

Alisha's Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 4075    Accepted Submission(s): 1052 Problem Description Princess Alisha invites her friends to come to her birthday party. Each

HDU3810 Magina(搜索+用优先队列模拟01背包)经典

Magina Time Limit: 60000/30000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 528    Accepted Submission(s): 177 Problem Description Magina, also known as Anti-Mage, is a very cool hero in DotA (Defense of the Anci

HDU 1873-看病要排队(优先队列+模拟乱搞)

看病要排队 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5042    Accepted Submission(s): 2073 Problem Description 看病要排队这个是地球人都知道的常识. 不过经过细心的0068的观察,他发现了医院里排队还是有讲究的.0068所去的医院有三个医生(汗,这么少)同时看病.而看病的人病

Problem E: 穷游中国在统题 优先队列 + 模拟

http://www.gdutcode.sinaapp.com/problem.php?cid=1049&pid=4 Problem E: 穷游中国在统题 Description Travel_poorly队是广工大目前最年轻的金牌队伍,队内成员分别是tmk.YFQ.Maple.这天他们接到教练的order要给新生杯统题,统题是个不轻松的工作,要评估各个题目的难度,设计出一套有梯度的套题,使得做题的情况有区分度.tmk很快想出了解决的办法,他给每道题目都设置了一个难度值,然后按照难度值进行筛选题

幸福列车(优先队列模拟)

幸福列车 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 2169    Accepted Submission(s): 672 Problem Description 一批幸福的列车即将从杭州驶向幸福的终点站——温州,身为总列车长的linle有一些奇怪的癖好.他会记录下全部乘客的名字(name)和他们的人品值(RP),根据这些将

HDU5437 Alisha’s Party (优先队列 + 模拟)

Alisha’s Party Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2650    Accepted Submission(s): 722 Problem Description Princess Alisha invites her friends to come to her birthday party. Each o

hdu 5441 优先队列+模拟 **

比赛的时候虽然考虑到没门的情况,但是写了几组都能过,就没想了,23333,差一行代码就能A,遗憾~~ 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #de

[模拟]ZOJ3485 Identification Number

题意:给了一串15位或18位的身份证号码,求 在改变最少位数的情况下, 输出正确合法的身份证号 合法的身份证 是按照以下规则: 前6位以及“Order code”三位  一定合法 其中X是根据前17位的值计算出来的 按照如下公式  (a1就是最后一位,若为10就是X) 另外 题目还规定了“Date of Birth” 要在1900.1.1到2011.4.2之间 刚开始想这题的时候,觉得15位也就只需要 改变 年月日6位 18位也就只需要 改变 年月日加X位9位而已 但是打起来发现并非这么简单..

BZOJ1029: [JSOI2007]建筑抢修[模拟 贪心 优先队列]

1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec  Memory Limit: 162 MBSubmit: 3785  Solved: 1747[Submit][Status][Discuss] Description 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有N个建筑设施受到了严重的损伤,如果不尽快修复的话,这些建筑设施将会完全毁坏.现在的情况是:T部落基地里只有一个修理工人