首页 > 学院 > 开发设计 > 正文

HDU 6011 Lotus and Characters

2019-11-08 01:33:25
字体:
来源:转载
供稿:网友

PRoblem DescriptionLotus has n kinds of characters,each kind of characters has a value and a amount.She wants to construct a string using some of these characters.Define the value of a string is:its first character's value*1+its second character's value *2+...She wants to calculate the maximum value of string she can construct.Since it's valid to construct an empty string,the answer is always ≥0。 InputFirst line is T(0≤T≤1000) denoting the number of test cases.For each test case,first line is an integer n(1≤n≤26),followed by n lines each containing 2 integers vali,cnti(|vali|,cnti≤100),denoting the value and the amount of the ith character. OutputFor each test case.output one line containing a single integer,denoting the answer. Sample Input
225 16 23-5 32 11 1 Sample Output
355 本来以为是个签到题,后来傻傻的掉了坑,一开始考虑的负数是直接排除情况的,后来才想到负数可以占位置,让后面的正数来乘以更大的基数,就是题中1,2,3……
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<algorithm>#include<vector>using namespace std;int n,T;int maxvalue;struct node{    int v,c;}p[30];int cmp(node a,node b){    return b.v>a.v;}int main(){    scanf("%d",&T);    while (T--)    {        int i,j,cnt,index,value;        cnt=value=0;        scanf("%d",&n);        for (i=0;i<n;i++)            scanf("%d%d",&p[i].v,&p[i].c);        sort(p,p+n,cmp);        int sum=0;        for (i=n-1;i>=0;i--)        {            for (j=0;j<p[i].c;j++)            {                sum+=p[i].v;                if (sum>0)                    value+=sum;                else                    break;            }            if (j<p[i].c)                break;        }        printf("%d/n",value);    }    return 0;}

Problem DescriptionLotus has n kinds of characters,each kind of characters has a value and a amount.She wants to construct a string using some of these characters.Define the value of a string is:its first character's value*1+its second character's value *2+...She wants to calculate the maximum value of string she can construct.Since it's valid to construct an empty string,the answer is always ≥0。 InputFirst line is T(0≤T≤1000) denoting the number of test cases.For each test case,first line is an integer n(1≤n≤26),followed by n lines each containing 2 integers vali,cnti(|vali|,cnti≤100),denoting the value and the amount of the ith character. OutputFor each test case.output one line containing a single integer,denoting the answer. Sample Input
225 16 23-5 32 11 1 Sample Output
355 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表