zoukankan      html  css  js  c++  java
  • BZOJ2748 [HAOI2012] 音量调节

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2748

    Description

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

    Input

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

    Output

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

    论水题的最高境界

    这真的是省选题?

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #define rep(i,l,r) for(int i=l; i<=r; i++)
     5 #define clr(x,y) memset(x,y,sizeof(x))
     6 using namespace std;
     7 int n,m,begin,c[60];
     8 bool f[60][1010];
     9 inline int read(){
    10     int ans = 0, f = 1;
    11     char c = getchar();
    12     while (!isdigit(c)){
    13         if (c == '-') f = -1;
    14         c = getchar();
    15     }
    16     while (isdigit(c)){
    17         ans = ans * 10 + c - '0';
    18         c = getchar();
    19     }
    20     return ans * f;
    21 }
    22 int main(){
    23     n = read(); begin = read(); m = read();
    24     rep(i,1,n) c[i] = read();
    25     clr(f,0); f[0][begin] = 1;
    26     rep(i,1,n){
    27         rep(j,0,m){
    28             if (j + c[i] <= m)
    29             if (f[i-1][j+c[i]]) f[i][j] = 1;
    30             if (j - c[i] >= 0)
    31             if (f[i-1][j-c[i]]) f[i][j] = 1;
    32         }
    33     }
    34     for(int i=m; i>=0; i--) if (f[n][i]){
    35         printf("%d
    ",i); return 0;
    36     }
    37     printf("-1
    ");
    38     return 0;
    39 }
    View Code
  • 相关阅读:
    vue单页面
    禁止系统默认右键并执行自己的程序
    jquery-ui拖动
    jquery鼠标右键功能 备忘
    日历插件 备忘
    兼容于苹果手机的点击方法
    js判断设备访问入口
    微信小程序点击显示某个view
    微信小程序数量减
    点外层div关闭,点里层不关闭
  • 原文地址:https://www.cnblogs.com/jimzeng/p/bzoj2748.html
Copyright © 2011-2022 走看看