zoukankan      html  css  js  c++  java
  • HDU 4091 Zombie’s Treasure Chest(2011ACM上海赛区预选赛第一题)

    Zombie’s Treasure Chest

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 994    Accepted Submission(s): 211


    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.
     
    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
     
    Source
     
    Recommend
    lcy
     
     
     
    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    long long gcd(long long da,long long xiao)
    {
    long long temp;
    while(xiao!=0)
    {
    temp=da%xiao;
    da=xiao;
    xiao=temp;
    }
    return da;
    }
    int main()
    {
    int iCase=0;
    int T;
    scanf("%d",&T);
    long long N,S1,V1,S2,V2;
    while(T--)
    {
    iCase++;
    scanf("%I64d%I64d%I64d%I64d%I64d",&N,&S1,&V1,&S2,&V2);
    long long tmp=S1*S2/gcd(S1,S2);
    long long res;
    long long tt=N/tmp;
    N=N%tmp;
    if(tt)
    {
    tt--;
    N+=tmp;
    }
    res=max((tt)*(tmp/S1)*V1,(tt)*(tmp/S2)*V2);
    long long res2=0;
    if(S2>S1)
    {
    long long t;
    t=S1;S1=S2;S2=t;
    t=V1;V1=V2;V2=t;
    }
    for(int i=0;i<=N/S1;i++)
    {
    if(res2<i*V1+(N-i*S1)/S2*V2)res2=i*V1+(N-i*S1)/S2*V2;
    }
    res+=res2;
    printf("Case #%d: %I64d\n",iCase,res);
    }
    return 0;
    }
  • 相关阅读:
    如何设定测试目标
    转载:Robotium之Android控件定位实践和建议(Appium/UIAutomator姊妹篇)
    Jenkins启动时报错:java.net.BindException: Address already in use: bind 解决方法
    [转载]Robotium API 翻译(三)——判断测试结果的方法assert、is、search
    什么样的项目适合开展自动化测试
    Python基础11- 函数之自定义函数
    Python基础10- 函数之内部函数与强制转换
    Android获取APK包名的几种方法
    Python基础9- 字典
    回归测试策略
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2240182.html
Copyright © 2011-2022 走看看