zoukankan      html  css  js  c++  java
  • 【智力大冲浪】

    【智力大冲浪】
    riddle
    内存限制: 128M
    【题目描述】
    例 1 智力大冲浪(riddle.pas)。
    【题目描述】
    小伟报名参加中央电视台的智力大冲浪节目。本次挑战赛吸引了众多
    参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者 m 元。先
    不要太高兴!因为这些钱还不一定都是你的。接下来主持人宣布了比
    赛规则:
    首先,比赛时间分为 n 个时段(n≤500),它又给出了很多小游戏,每
    个小游戏都必须在规定期限 ti 前完成(1≤ti≤n)。如果一个游戏没能
    在规定期限前完成,则要从奖励费 m 元中扣去一部分钱 wi, wi 为自
    然数,不同的游戏扣去的钱是不一样的。当然,每个游戏本身都很简
    单,保证每个参赛者都能在一个时段内完成,而且都必须从整时段开
    始。主持人只是想考考每个参赛者如何安排组织自己做游戏的顺序。
    作为参赛者,小伟很想赢得冠军,当然更想赢取最多的钱!
    注意:比赛绝对不会让参赛者赔钱!
    【输入】
    输入文件 riddle.in,共 4 行。
    第一行为 m,表示一开始奖励给每位参赛者的钱;
    第二行为 n,表示有 n 个小游戏;
    第三行有 n 个数,分别表示游戏 1~n 的规定完成期限;
    第四行有 n 个数,分别表示游戏 1~n 不能在规定期限前完成的扣
    数。
    【输出】
    输出文件 riddle.out,仅 1 行。表示小伟能赢取最多的钱。
    【样例输入】
    10000
    7
    4 2 4 3 1 4 6
    70 60 50 40 30 20 10
    【样例输出】
    9950

    题解:
    损失的最少,等价于先都减去再加回来,再跑一遍01背包。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<vector>
     6 #include<map>
     7 #include<set>
     8 #include<cmath>
     9 #include<ctime>
    10 #define inf 2147483647
    11 #define p(a) putchar(a)
    12 #define g() getchar()
    13 #define For(i,a,b) for(register int i=a;i<=b;i++)
    14 //by war
    15 //2017.10.24
    16 using namespace std;
    17 int m;
    18 int n;
    19 //int t[510];
    20 //int v[510];
    21 int f[510];
    22 int Max;
    23 struct jl
    24 {
    25     int t;
    26     int v;
    27     bool operator<(const jl&aa)const
    28     {
    29         return t<aa.t;
    30     }
    31 }a[510];
    32 
    33 void in(int &x)
    34 {
    35     int y=1;
    36     char c=g();x=0;
    37     while(c<'0'||c>'9')
    38     {
    39         if(c=='-')
    40         y=-1;
    41         c=g();
    42     }
    43     while(c>='0'&&c<='9')x=x*10+c-'0',c=g();
    44     x*=y;
    45 }
    46 void o(int x)
    47 {
    48     if(x<0)
    49     {
    50     p('-');
    51     x=-x;
    52     }
    53     if(x>9)o(x/10);
    54     p(x%10+'0');
    55 }
    56 int main()
    57 {
    58     freopen("riddle.in","r",stdin);
    59     freopen("riddle.out","w",stdout);
    60     in(m),in(n);
    61     For(i,1,n)
    62     in(a[i].t);    
    63     For(i,1,n)
    64     in(a[i].v),m-=a[i].v;
    65     sort(a+1,a+n+1);
    66     For(i,1,n)
    67       for(register int j=a[i].t;j>=1;j--)
    68         f[j]=max(f[j],f[j-1]+a[i].v);
    69     Max=-inf;
    70     For(i,1,n)
    71     Max=max(Max,f[i]);
    72     o(Max+m);
    73     return 0;
    74 }
  • 相关阅读:
    react 在IE9下input标签使用e.target.value取值失败
    mingw-w64 about
    Cygwin .a 转为 .lib .dll
    windows terminal
    ssh key authentication
    sshd_config 2
    sshd_config
    bash sudo redirect multiple lines to file
    计算几何
    vs cli
  • 原文地址:https://www.cnblogs.com/war1111/p/7722789.html
Copyright © 2011-2022 走看看