codeforces 417A A. Elimination
2017-08-18 18:43
267 查看
A. Elimination
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.
The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners
of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems.
The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination.
As a result of all elimination rounds at least n·m people should go to the finals. You need to organize elimination rounds
in such a way, that at least n·m people go to the finals, and the total amount of used problems i
4000n all rounds is as small
as possible.
Input
The first line contains two integers c and d (1 ≤ c, d ≤ 100) —
the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≤ n, m ≤ 100).
Finally, the third line contains an integer k (1 ≤ k ≤ 100) —
the number of the pre-chosen winners.
Output
In the first line, print a single integer — the minimum number of problems the jury needs to prepare.
Examples
input
output
input
output
题意:最终的比赛需要有n*m个队伍参加,有保送的k个队伍,有主选拔方式需要出c个问题,选出n个队伍,有次选拔方式,出d个问题,选拔一个人。求最少需要出几个问题。
思路比较两种方式的价值,其实是一个简单的完全背包,但是比赛的时候一直没有写对。其实不用背包写,也是很简单的一个问题。
主形式选拔方式:c个问题,n个人
次选拔方式:d个问题,1个人
所以可以得出用次形式选拔n个人需要n*d个问题,所以只需要比较c和n*d,选择比较小的一个。
最后的细节需要处理一下。
在下边再贴上一种背包的代码。
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.
The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners
of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems.
The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination.
As a result of all elimination rounds at least n·m people should go to the finals. You need to organize elimination rounds
in such a way, that at least n·m people go to the finals, and the total amount of used problems i
4000n all rounds is as small
as possible.
Input
The first line contains two integers c and d (1 ≤ c, d ≤ 100) —
the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≤ n, m ≤ 100).
Finally, the third line contains an integer k (1 ≤ k ≤ 100) —
the number of the pre-chosen winners.
Output
In the first line, print a single integer — the minimum number of problems the jury needs to prepare.
Examples
input
1 10 7 2 1
output
2
input
2 22 1
2
output
0
题意:最终的比赛需要有n*m个队伍参加,有保送的k个队伍,有主选拔方式需要出c个问题,选出n个队伍,有次选拔方式,出d个问题,选拔一个人。求最少需要出几个问题。
思路比较两种方式的价值,其实是一个简单的完全背包,但是比赛的时候一直没有写对。其实不用背包写,也是很简单的一个问题。
主形式选拔方式:c个问题,n个人
次选拔方式:d个问题,1个人
所以可以得出用次形式选拔n个人需要n*d个问题,所以只需要比较c和n*d,选择比较小的一个。
最后的细节需要处理一下。
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #define N 2005 using namespace std; int c,d,n,m,k; int main() { scanf("%d %d %d %d %d",&c,&d,&n,&m,&k); int sum; sum=n*m-k; if(sum<=0){ printf("0\n"); return 0; } int ans; int t=sum/n; int aa=sum%n; ans=t*min(c,n*d)+min(aa*d,c); printf("%d\n",ans); return 0; }
在下边再贴上一种背包的代码。
#include <cstdio> #include <cstring> #define inf 0x3f3f3f3f #define N 10005 int f ,c,d,n,m,k; inline int min(int x,int y){return x<y?x:y;} int main() { scanf("%d %d %d %d %d",&c,&d,&n,&m,&k); if(n*m<=k){puts("0");return 0;} memset(f,inf,sizeof(f));f[0]=0; for(int i=1;i<=n*m;++i){ if(i>=n) f[i]=f[i-n]+c; f[i]=min(f[i],f[i-1]+d); } for(int i=1;i<=n*m;i++) { printf("%d ",f[i]); } printf("\n"); int ans=inf; for(int i=n*m-k;i<=n*m;++i) if(f[i]<ans) ans=f[i]; printf("%d\n",ans); return 0; }
相关文章推荐
- 【dp】 Codeforces 2B
- CodeForces 523C
- CodeForces 617B Chocolate
- CodeForces 645B Mischievous Mess Makers
- Codeforces963C Frequency of String 【字符串】【AC自动机】
- codeforces 762E(cdq分治)
- CodeForces 852E Casinos and travel(思维)
- 解题报告 codeforces 242A
- Codeforces 523D Statistics of Recompressing Videos 排序+优先队列
- codeforces 664B B. Rebus(乱搞题)
- Codeforces 500A:New Year Transportation(水题)
- 【Codeforces】113 D. Museum
- Codeforces 798C Mike and gcd problem gcd+贪心
- CodeForces - 864A Fair Game
- codeforces 245C Game with Coins
- [codeforces 519E]E. A and B and Lecture Rooms(树上倍增)
- codeforces 425A Sereja and Swaps
- Codeforces 718C Sasha and Array(线段树维护矩阵)
- [Codeforces 888G]Xor-MST
- Codeforces 798D Mike and distribution 构造