Coder-Strike 2014 - Round 2 C. Jeopardy!
2014-04-21 00:00
309 查看
摘要: Coder-Strike 2014 - Round 2 C
题目:
C. Jeopardy!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2.
The finals will have n questions, m of them are auction questions and n - m of them are regular questions. Each question has a price. The price of the i-th question is ai points. During the game the players chose the questions. At that, if the question is an auction, then the player who chose it can change the price if the number of his current points is strictly larger than the price of the question. The new price of the question cannot be less than the original price and cannot be greater than the current number of points of the player who chose the question. The correct answer brings the player the points equal to the price of the question. The wrong answer to the question reduces the number of the player's points by the value of the question price.
The game will go as follows. First, the R2 company selects a question, then the questions are chosen by the one who answered the previous question correctly. If no one answered the question, then the person who chose last chooses again.
All R2 employees support their team. They want to calculate what maximum possible number of points the R2 team can get if luck is on their side during the whole game (they will always be the first to correctly answer questions). Perhaps you are not going to be surprised, but this problem was again entrusted for you to solve.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107)— the prices of the questions. The third line contains m distinct integers bi (1 ≤ bi ≤ n) — the numbers of auction questions. Assume that the questions are numbered from 1 to n.
Output
In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
Sample test(s)
input
output
input
output
input
output
代码:
解析:
贪心算法,要尽量使可变的auction questions获得更大的数值,因此以让当前的数值增长最快为准则做出贪心选择
题目:
C. Jeopardy!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2.
The finals will have n questions, m of them are auction questions and n - m of them are regular questions. Each question has a price. The price of the i-th question is ai points. During the game the players chose the questions. At that, if the question is an auction, then the player who chose it can change the price if the number of his current points is strictly larger than the price of the question. The new price of the question cannot be less than the original price and cannot be greater than the current number of points of the player who chose the question. The correct answer brings the player the points equal to the price of the question. The wrong answer to the question reduces the number of the player's points by the value of the question price.
The game will go as follows. First, the R2 company selects a question, then the questions are chosen by the one who answered the previous question correctly. If no one answered the question, then the person who chose last chooses again.
All R2 employees support their team. They want to calculate what maximum possible number of points the R2 team can get if luck is on their side during the whole game (they will always be the first to correctly answer questions). Perhaps you are not going to be surprised, but this problem was again entrusted for you to solve.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107)— the prices of the questions. The third line contains m distinct integers bi (1 ≤ bi ≤ n) — the numbers of auction questions. Assume that the questions are numbered from 1 to n.
Output
In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
Sample test(s)
input
4 1 1 3 7 5 3
output
18
input
3 2 10 3 8 2 3
output
40
input
2 2 100 200 1 2
output
400
代码:
#include <iostream> #include <algorithm> using namespace std; int n , m; int i, j; long long int tmp, ans = 0; int stab[200]; int tmptab[200]; int main() { cin >> n >> m; for(i = 1; i <= n; i++){ cin >> tmptab[i]; ans += tmptab[i]; } for(i = 1, j = 1; i <= m; i++){ cin >> tmp; ans -= tmptab[tmp]; stab[j++] = tmptab[tmp]; } sort(stab + 1, stab + m + 1); for(j = m; j >= 1; j++){ tmp = stab[i]; if(ans > stab[i]) ans += ans; else ans += stab[i]; } cout << ans << "\n"; return 0; }
解析:
贪心算法,要尽量使可变的auction questions获得更大的数值,因此以让当前的数值增长最快为准则做出贪心选择
相关文章推荐
- Coder-Strike 2014 - Round 1 C. Pattern
- Coder-Strike 2014 - Qualification Round C. Kicker(推理题)
- Coder-Strike 2014 - Round 1 E. E-mail Addresses
- Coder-Strike 2014 - Round 1
- Coder-Strike 2014 - Round 2
- Coder-Strike 2014 - Qualification Round A. Password Check(简单字符串)
- Coder-Strike 2014 - Round 1(A~E)
- Coder-Strike 2014 - Round 1
- Coder-Strike 2014 - Round 1 D. Giving Awards
- codeforces Coder-Strike 2014 Round 1 C题解题报告
- codeforces Coder-Strike 2014 Round 1 B题解题报告
- Coder-Strike 2014 - Round 2
- Coder-Strike 2014 - Round 1 D. Giving Awards
- Coder-Strike 2014 - Round 1__Giving Awards
- Coder-Strike 2014 - Qualification Round——A. Password Check
- codeforces Coder-Strike 2014 Round 1 A题解题报告
- 【索引】Coder-Strike 2014 - Round 1
- Coder-Strike 2014 - Round 2
- Coder-Strike 2014 - Round 1__E-mail Addresses
- 模拟 Coder-Strike 2014 - Round 1 A. Poster