zoukankan      html  css  js  c++  java
  • [HAOI 2012]音量调节

    Description

    一个吉他手准备参加一场演出。他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都要改变一次音量。在演出开始之前,他已经做好了一个列表,里面写着在每首歌开始之前他想要改变的音量是多少。每一次改变音量,他可以选择调高也可以调低。
    音量用一个整数描述。输入文件中给定整数beginLevel,代表吉他刚开始的音量,以及整数maxLevel,代表吉他的最大音量。音量不能小于0也不能大于maxLevel。输入文件中还给定了n个整数c1,c2,c3…..cn,表示在第i首歌开始之前吉他手想要改变的音量是多少。
    吉他手想以最大的音量演奏最后一首歌,你的任务是找到这个最大音量是多少。

    Input

    第一行依次为三个整数:n, beginLevel, maxlevel。
    第二行依次为n个整数:c1,c2,c3…..cn。

    Output

    输出演奏最后一首歌的最大音量。如果吉他手无法避免音量低于0或者高于maxLevel,输出-1。

    Sample Input

    3 5 10
    5 3 7

    Sample Output

    10

    HINT

    1<=N<=50,1<=Ci<=Maxlevel 1<=maxlevel<=1000
    0<=beginlevel<=maxlevel

    题解

    自古蛤省出水题。拿个$bool$背包乱搞一下就好了。没事干还可以滚一下。

     1 //It is made by Awson on 2017.11.5
     2 #include <set>
     3 #include <map>
     4 #include <cmath>
     5 #include <ctime>
     6 #include <stack>
     7 #include <queue>
     8 #include <vector>
     9 #include <string>
    10 #include <cstdio>
    11 #include <cstdlib>
    12 #include <cstring>
    13 #include <iostream>
    14 #include <algorithm>
    15 #define LL long long
    16 #define Min(a, b) ((a) < (b) ? (a) : (b))
    17 #define Max(a, b) ((a) > (b) ? (a) : (b))
    18 #define Abs(x) ((x) < 0 ? (-(x)) : (x))
    19 using namespace std;
    20 const int N = 50;
    21 const int M = 1000;
    22 
    23 bool f[M+5][N+5], t, lt;
    24 int n, b, m, c;
    25 
    26 void work() {
    27     scanf("%d%d%d", &n, &b, &m); t = 1; f[b][lt] = 1;
    28     for (int i = 1; i <= n; i++) {
    29         scanf("%d", &c);
    30         for (int j = 0; j <= m; j++) {
    31             f[j][t] = 0;
    32             if (j-c >= 0) f[j][t] |= f[j-c][lt];
    33             if (j+c <= m) f[j][t] |= f[j+c][lt];
    34         }
    35         swap(t, lt);
    36     }
    37     for (int i = m; i >= 0; i--) if (f[i][lt]) {
    38         printf("%d
    ", i); return;
    39     }
    40     printf("%d
    ", -1);
    41 }
    42 int main() {
    43     work();
    44     return 0;
    45 }
  • 相关阅读:
    Nginx proxy开启cache缓存
    Nginx Server 配置
    nginx 全局配置
    Nginx 配置文件解析
    Python-Scrapy框架
    Python-shutil模块
    os模块3
    os模块
    python os模块atime ,ctime,mtime意义
    Python-正则表达式
  • 原文地址:https://www.cnblogs.com/NaVi-Awson/p/7787580.html
Copyright © 2011-2022 走看看