zoukankan      html  css  js  c++  java
  • LightOJ1106 Gone Fishing

    Gone Fishing

    John is going on a fishing trip. He has h hours available, and there are n lakes in the area all reachable along a single, one-way road. John starts at lake 1, but he can finish at any lake he wants. He can only travel from one lake to the next one, but he does not have to stop at any lake unless he wishes to. For each i (1 to n-1), the number of 5-minute intervals it takes to travel from lake i to lake i+1 is denoted ti. For example, t3=4 means that it takes 20 minutes to travel from lake 3 to 4.

    To help plan his fishing trip, John has gathered some information about the lakes. For each lake i, the number of fish expected to be caught in the initial 5 minutes, denoted fi, is known. Each 5 minutes of fishing decreases the number of fish expected to be caught in the next 5-minute interval by a constant rate of di. If the number of fish expected to be caught in an interval is less than or equal to di, there will be no more fish left in the lake in the next interval. To simplify the planning, John assumes that no one else will be fishing at the lakes to affect the number of fish he expects to catch. Write a program to help John plan his fishing trip to maximize the number of fish expected to be caught. The number of minutes spent at each lake must be a multiple of 5.

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with a line containing two integers n (2 ≤ n ≤ 25) and h (1 ≤ h ≤ 16). Next, there is a line of n integers specifying fi (0 ≤ fi ≤ 1000), then a line of n integers di (0 ≤ di ≤1000), and finally, a line of n-1 integers denoting ti (0 < ti < 192).

    Output

    For each test case, print the case number first. Then print the number of minutes spent at each lake, separated by commas, for the plan achieving the maximum number of fish expected to be caught. This is followed by a line containing the number of fish expected. If multiple plans exist, choose the one that spends as long as possible at lake 1. If there is still a tie, choose the one that spends as long as possible at lake 2, and so on.

    Sample Input

    3

    2 1

    10 1

    2 5

    2

    4 4

    10 15 20 17

    0 3 4 3

    1 2 3

    4 4

    10 15 50 30

    0 3 4 3

    1 2 3

    Sample Output

    Case 1:

    45, 5

    Number of fish expected: 31

    Case 2:

    240, 0, 0, 0

    Number of fish expected: 480

    Case 3:

    115, 10, 50, 35

    Number of fish expected: 724

    好奇怪的题

    看上去像是背包,后来发现似乎时间不够

    然后发现可以枚举停在哪里,然后用堆维护在1到k钓鱼的时候怎么钓

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<algorithm>
     6 #include<cmath>
     7 #include<queue>
     8 #include<deque>
     9 #include<set>
    10 #include<map>
    11 #include<ctime>
    12 #define LL long long
    13 #define inf 0x7ffffff
    14 #define pa pair<int,int>
    15 #define mkp(a,b) make_pair(a,b)
    16 #define pi 3.1415926535897932384626433832795028841971
    17 using namespace std;
    18 inline LL read()
    19 {
    20     LL x=0,f=1;char ch=getchar();
    21     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    22     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    23     return x*f;
    24 }
    25 inline void write(LL a)
    26 {
    27     if (a<0){printf("-");a=-a;}
    28     if (a>=10)write(a/10);
    29     putchar(a%10+'0');
    30 }
    31 inline void writeln(LL a){write(a);printf("
    ");}
    32 int n,m,ans,len;
    33 int v[30],w[30],t[30];
    34 int f[210];
    35 int sv[30];
    36 int wk[30];
    37 priority_queue<pa,vector<pa>,greater<pa> >q;
    38 inline void solve(int k)
    39 {
    40     while (!q.empty())q.pop();
    41     memset(wk,0,sizeof(wk));
    42     for (int i=1;i<=k;i++)q.push(mkp(-v[i],i));
    43     int rest=m-t[k],sum=0;
    44     if (rest<=0)return;
    45     while (rest&&!q.empty())
    46     {
    47         int v=-q.top().first,id=q.top().second;
    48         //printf("q %d %d
    ",v,id);
    49         q.pop();
    50         sum+=v;
    51         wk[id]++;
    52         if (v>w[id])q.push(mkp(-(v-w[id]),id));else q.push(mkp(0,id));
    53         rest--;
    54     }
    55     if (sum>ans){len=k;ans=sum;for (int i=1;i<=n;i++)sv[i]=wk[i];return;}
    56     if (sum<ans)return;
    57     bool mrk=0;
    58     for (int i=1;i<=k;i++)
    59     {
    60         if (wk[i]>sv[i])mrk=1;
    61         if (wk[i]!=sv[i])break;
    62     }
    63     if (mrk){len=k;ans=sum;for (int i=1;i<=n;i++)sv[i]=wk[i];return;}
    64     return;
    65 }
    66 inline void work(int cur)
    67 {
    68     n=read();m=read()*12;
    69     memset(sv,0,sizeof(sv));
    70     ans=0;
    71     for (int i=1;i<=n;i++)v[i]=read();
    72     for (int i=1;i<=n;i++)w[i]=read();
    73     for (int i=2;i<=n;i++)t[i]=read()+t[i-1];
    74     for (int i=1;i<=n;i++)solve(i);
    75     printf("Case %d:
    ",cur);
    76     for (int i=1;i<n;i++)printf("%d, ",5*sv[i]);
    77     printf("%d
    ",5*sv[n]);
    78     printf("Number of fish expected: %d
    ",ans);
    79 }
    80 int main()
    81 {
    82     int T=read(),tt=0;while (T--)work(++tt);
    83 }
    LightOJ 1106
    ——by zhber,转载请注明来源
  • 相关阅读:
    Subclipse安装及应用【eclipse 3.7 + subclipse1.8】
    淘宝有病!
    集装箱货柜号码 公式算法
    自己网站利用支付宝结算时的说明
    发现安全卫士360影响电脑正常运行
    中国银行的动态口令
    c#中的接口(interface)到底应用在哪些地方?
    淘宝有病(二)
    What 's CATT(Computer Aided Test Tool)?How to deal with the CATT in the SAP System?什么是CATT(计算机附加测试工具)
    Consultanting Service
  • 原文地址:https://www.cnblogs.com/zhber/p/7152872.html
Copyright © 2011-2022 走看看