zoukankan      html  css  js  c++  java
  • Codeforces 964B(贪心)

        题目链接:点击打开链接
        题目描述:
    B. Messages
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. After reading the message, Vasya's bank account receives the current cost of this message. Initially, Vasya's bank account is at 0.

    Also, each minute Vasya's bank account receives C·k, where k is the amount of received but unread messages.

    Vasya's messages are very important to him, and because of that he wants to have all messages read after T minutes.

    Determine the maximum amount of money Vasya's bank account can hold after T minutes.

    Input

    The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000).

    The second string contains n integers ti (1 ≤ ti ≤ T).

    Output

    Output one integer  — the answer to the problem.

    Examples
    Input
    Copy
    4 5 5 3 5
    1 5 5 4
    Output
    Copy
    20
    Input
    Copy
    5 3 1 1 3
    2 2 2 1 1
    Output
    Copy
    15
    Input
    Copy
    5 5 3 4 5
    1 2 3 4 5
    Output
    Copy
    35
    Note

    In the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total.

    In the second sample the messages can be read at any integer moment.

    In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at the corresponding minutes, he gets 40 points for them. When reading messages, he receives (5 - 4·3) + (5 - 3·3) + (5 - 2·3) + (5 - 1·3) + 5 =  - 5 points. This is 35 in total.



     
        解释下题意:你有n封信,每封信最开始的价值为A,第i封信要在第ti秒后才能够接收,每当一封信被接收之后,他的价值每分钟就会减少B元。而每分钟Vasya可以获得的利润是C*k k为接收了但未读的信。求出Vasya可获得的最大利润。
        分析题意:因为要求获得的最大利润,故我们不妨采用贪心的策略。因为当接收到一份信后,这封信损失的和Vasya所获得的应该是一一对应的关系,即当Vasya获得了C*k元时,同时她也会损失掉B*k的钱。
        因此,考虑到最差的情况,即当获得的利润C小于B时,我们贪心的取最初的值,即总价值为n*A。
        而当可获得的利润C大于B的时候,我们可以枚举所有的信,贪心使每一封信保存时间最长,并乘上利润,并累加,即可获得最终的答案。
        
        ps:当时打的时候没有审清楚题,(;´д`)ゞ,导致被hack了( ̄▽ ̄)",看来得注意看下面的样例解释才行了
        
    #include <bits/stdc++.h>
    #define maxn 1005
    using namespace std;
    int num[maxn];
    int main()
    {
    	int n,a,b,c,t;
    	cin>>n>>a>>b>>c>>t;
    	for(int i=0;i<n;i++){
            cin>>num[i];//输入时间
    	}
    	int res=0;
    	res+=n*a;//最差的情况,即全都在接收信后立即得到价值
    	if(b<c){//如果增加的利润大于减小的利润(即答案还能更优)
            for(int i=0;i<n;i++){
                res+=(t-num[i])*(c-b);//统计答案
            }
    	}
    	cout<<res<<endl;
        return 0;
    }



  • 相关阅读:
    JQuery第一部分
    linq高级查与分页
    怎么修改数据库信息例子
    怎样连接客户端和操作数据库
    php数组的合并与方法
    php函数与数组
    php变量类型,运算符与表达式
    php正则表达式
    数组和字符串的几种常见替代方法
    php变量,类型和表达式
  • 原文地址:https://www.cnblogs.com/Chen-Jr/p/11007316.html
Copyright © 2011-2022 走看看