HDU4091(2011 Asia Shanghai Regional Contest)
Zombie’s Treasure Chest
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4085 Accepted Submission(s): 836
Problem Description
Some brave warriors come to a lost village. They are very lucky and find a lot of treasures and a big treasure chest, but with angry zombies.
The warriors are so brave that they decide to defeat the zombies and then bring all the treasures back. A brutal long-drawn-out battle lasts from morning to night and the warriors find the zombies are undead and invincible.
Of course, the treasures should not be left here. Unfortunately, the warriors cannot carry all the treasures by the treasure chest due to the limitation of the capacity of the chest. Indeed, there are only two types of treasures: emerald and sapphire. All of the emeralds are equal in size and value, and with infinite quantities. So are sapphires.
Being the priest of the warriors with the magic artifact: computer, and given the size of the chest, the value and size of each types of gem, you should compute the maximum value of treasures our warriors could bring back.
The warriors are so brave that they decide to defeat the zombies and then bring all the treasures back. A brutal long-drawn-out battle lasts from morning to night and the warriors find the zombies are undead and invincible.
Of course, the treasures should not be left here. Unfortunately, the warriors cannot carry all the treasures by the treasure chest due to the limitation of the capacity of the chest. Indeed, there are only two types of treasures: emerald and sapphire. All of the emeralds are equal in size and value, and with infinite quantities. So are sapphires.
Being the priest of the warriors with the magic artifact: computer, and given the size of the chest, the value and size of each types of gem, you should compute the maximum value of treasures our warriors could bring back.
Input
There are multiple test cases. The number of test cases T (T <= 200) is given in the first line of the input file. For each test case, there is only one line containing five integers N, S1, V1, S2, V2, denoting the size of the treasure chest is N and the
size and value of an emerald is S1 and V1, size and value of a sapphire is S2, V2. All integers are positive and fit in 32-bit signed integers.
Output
For each test case, output a single line containing the case number and the maximum total value of all items that the warriors can carry with the chest.
Sample Input
2
100 1 1 2 2
100 34 34 5 3
Sample Output
Case #1: 100
Case #2: 86
線性規劃題目,由於只能取整點 最優點可能取不到 ,因此索性將容量分為兩部分:
1)可以恰好裝翡翠或者藍寶石的
2)剩下的部分
第一部分直接取兩者總利潤的最大值
第二部分直接列舉 看取那種最好
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
int cas;
__int64 n,s1,v1,s2,v2;
scanf("%d",&cas);
for(int j=1;j<=cas;j++){
scanf("%I64d%I64d%I64d%I64d%I64d",&n,&s1,&v1,&s2,&v2);
__int64 tot=n/(s1*s2);
__int64 n1=tot*(s1*s2);
__int64 val=0;
if(tot*(s1*s2)/s1*v1>tot*(s1*s2)/s2*v2)
val=tot*(s1*s2)/s1*v1;
else
val=tot*(s1*s2)/s2*v2;
__int64 val2=0;
__int64 n2=n-n1;
if(s1>s2){
for(int i=0;i*s1<=n2;i++){
__int64 ans=i*v1+(n2-i*s1)/s2*v2;
if(val2<ans)
val2=ans;
}
}
else{
for(int i=0;i*s2<=n2;i++){
__int64 ans=i*v2+(n2-i*s2)/s1*v1;
if(ans>val2)
val2=ans;
}
}
//cout<<n1<<" "<<n2<<endl;
//cout<<val<<" "<<val2<<endl;
printf("Case #%d: %I64d\n",j,val+val2);
}
return 0;
}
相關文章
- The 2021 ICPC Asia Shenyang Regional Contest
- The 2024 ICPC Asia Nanjing Regional ContestNaN
- The 2022 ICPC Asia Nanjing Regional ContestNaN
- The 2023 ICPC Asia Macau Regional ContestMac
- The 2022 ICPC Asia Xian Regional Contest
- The 2022 ICPC Asia Hangzhou Regional Programming Contest
- The 2022 ICPC Asia Xian Regional Contest 前六題
- HDU3714 Error Curves(2010 Asia Chengdu Regional Contest)Error
- 2016-2017 ACM-ICPC Asia-Bangkok Regional ContestACM
- 2018-2019 ACM-ICPC, Asia Seoul Regional Contest——A - CircuitsACMUI
- The 2022 ICPC Asia Nanjing Regional Contest IGDA,和令人疑惑的MNaN
- The 2023 ICPC Asia Hangzhou Regional Contest (The 2nd Universal Cup. Stage 22: Hangzhou)
- Chayas - 2023-2024 ICPC, Asia Yokohama Regional Contest 2023, Problem E
- HDU 5052 Yaoge’s maximum profit 光禿禿的樹鏈拆分 2014 ACM/ICPC Asia Regional Shanghai Online...ACMAI
- The 2023 ICPC Asia Jinan Regional Contest (The 2nd Universal Cup. Stage 17: Jinan)補題記錄NaN
- 2017 ACM/ICPC Asia Regional Shenyang Online - 做題記錄ACM
- 2013 ACM/ICPC Asia Regional Online —— Warmup2 兩個水題ACM
- HDU4998 Rotate (2014 ACM/ICPC Asia Regional Anshan Online)ACM
- The 2023 ICPC Asia EC Regionals Online Contest (I)
- The 2024 ICPC Asia East Continent Online Contest (I)AST
- 2015 ACM/ICPC Asia Regional Shenyang Online-1012 Largest PointACM
- 2017-2018 ACM-ICPC Southeast Regional Contest (Div. 1)ACMAST
- 2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)ACM
- 2017-2018 ACM-ICPC, Central Europe Regional Contest (CERC 17)ACM
- HDU5023A Corrupt Mayor's Performance Art (2014 ACM/ICPC Asia Regional Guangzhou Online)ORMACM
- The 2024 ICPC Asia EC Regionals Online Contest (II) - Problem B. Mountain BookingAI
- The 2024 ICPC Asia EC Regionals Online Contest (II) - Problem H. Points Selection
- 2017-2018 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2017)ACM
- 2016-2017 ACM-ICPC Northwestern European Regional Programming Contest (NWERC 2016)ACM
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016)ACM
- 離職shanghai hongguan記AI
- Recruitment-- JAVA Engineer--ShanghaiUIJavaAI
- 2019-2020 ICPC Southeastern European Regional Programming Contest (SEERC 2019) 補題記錄AST
- Recruitment-- Senior Java Developer--ShanghaiUIJavaDeveloperAI
- 2020-2021 ICPC NERC (NEERC), North-Western Russia Regional Contest (Northern Subregionals) E(離散化+尤拉回路)
- Pegging a sub strapon in Shanghai/Suzhou/WuxiAIUX
- Get yourself a femdom Superior If you are truly submissive in ShanghaiAI
- Agile PLM 9.3 BootCamp Training - ShanghaibootAI