BestCoder Round #91

来源:互联网 发布:通过网络被骗的案例 编辑:程序博客网 时间:2024/05/18 01:29

Lotus and Characters

 
 Accepts: 150
 
 Submissions: 897
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 262144/131072 K (Java/Others)
问题描述
Lotus有nn种字母,给出每种字母的价值以及每种字母的个数限制,她想构造一个任意长度的串。定义串的价值为:第1位字母的价值*1+第2位字母的价值*2+第3位字母的价值*3……求Lotus能构造出的串的最大价值。(可以构造空串,因此答案肯定\geq 00
输入描述
第一行是数据组数T(0 \leq T \leq 1000)T(0T1000)。对于每组数据,第一行一个整数n(1 \leq n \leq 26)n(1n26),接下来nn行,每行2个整数val_i,cnt_i(|val_i|,cnt_i\leq 100)vali,cnti(vali,cnti100),分别表示第ii种字母的价值和个数限制。
输出描述
对于每组数据,输出一行一个整数,表示答案。
输入样例
225 16 23-5 32 11 1
输出样例
355

水题--有hack点--
1
2
-2 2
1 3

代码:


#include<stdio.h>#include<string>#include<stack>#include<queue>#include<math.h>#include<string.h>#include<algorithm>using namespace std;#define LL long longLL gcd(LL a, LL b){    if (a%b==0)        return b;    return gcd(b,a%b);}struct node{    int a,b;}pp[30];bool cmp(node x, node y){    return x.a<y.a;}int main(){    int n,t;    scanf("%d",&t);    while (t--)    {        scanf("%d",&n);        for (int i=0;i<n;i++)            scanf("%d%d",&pp[i].a,&pp[i].b);        sort(pp,pp+n,cmp);        int ans=0,lp=1,he=0;        for (int i=n-1;i>=0;i--)        {            for (int j=0;j<pp[i].b;j++)            {                if (pp[i].a+he>0)                {                    ans+=he+pp[i].a;                    he+=pp[i].a;                }            }        }        printf("%d\n",ans);    }    return 0;}







Lotus and Horticulture

 
 Accepts: 91
 
 Submissions: 641
 Time Limit: 4000/2000 MS (Java/Others)
 
 Memory Limit: 262144/262144 K (Java/Others)
问题描述
这几天Lotus对培养盆栽很感兴趣,于是她想搭建一个温室来满足她的研究欲望。Lotus将所有的nn株盆栽都放在新建的温室里,所以所有盆栽都处于完全相同的环境中。每一株盆栽都有一个最佳生长温度区间[l,r][l,r],在这个范围的温度下生长会生长得最好,但是不一定会提供最佳的研究价值(Lotus认为研究发育不良的盆栽也是很有研究价值的)。Lotus进行了若干次试验,发现若第ii株盆栽的生长温度适宜,可以提供a_iai的研究价值;若生长温度超过了适宜温度的上限,能提供b_ibi的研究价值;若生长温度低于适宜温度的下限,则能提供c_ici的研究价值。现在通过试验,Lotus已经得知了每一株盆栽的适宜生长温度范围,也知道了它们的aabbcc的值。你需要根据这些信息,给温室选定一个温度(这个温度可以是任意实数),使得Lotus能获得的研究价值最大。
输入描述
多组数据,第一行一个整数TT表示数据组数每组数据第一行一个整数n\in[1,50000]n[1,50000],表示盆栽数量接下来nn行每行五个整数l_i,r_i,a_i,b_i,c_i\in[1, 10^9]li,ri,ai,bi,ci[1,109],意义如上所述
输出描述
每组数据输出一行一个整数表示答案
输入样例
155 8 16 20 1210 16 3 13 138 11 13 1 117 9 6 17 52 11 20 8 5
输出样例
83

伪离散化--
-.-开始没有考虑左边界和右边界----只是直接跳过边界---终判GG

代码:

#include<stdio.h>#include<string>#include<stack>#include<queue>#include<math.h>#include<string.h>#include<algorithm>using namespace std;#define LL __int64struct node{    LL a,b,c;int l,r;}pp[60000];struct nn{    int shu,hao;}kk[120000];bool cmp1(nn x,nn y){    if (x.shu!=y.shu)    return x.shu<y.shu;    return x.hao%2<y.hao%2;}int main(){    int n,t;    scanf("%d",&t);    while (t--)    {        scanf("%d",&n);        int lp=0;        LL ans=0,da=0;        for (int i=0;i<n;i++)        {            scanf("%d%d%I64d%I64d%I64d",&pp[i].l,&pp[i].r,&pp[i].a,&pp[i].b,&pp[i].c);            kk[lp].hao=lp;kk[lp++].shu=pp[i].l;kk[lp].hao=lp;kk[lp++].shu=pp[i].r;            ans+=pp[i].c;        }        da=ans;        sort(kk,kk+lp,cmp1);        int kp=0,hh,xun;        for (int i=0;i<lp;i++)        {            xun=1;            if (kk[i].hao%2==0)            {                xun=1;                while (xun)                {                    hh=kk[i].hao/2;                    ans+=pp[hh].a-pp[hh].c;xun=0;                    if (i!=lp-1&&kk[i+1].shu==kk[i].shu&&kk[i+1].hao%2==kk[i].hao%2)                    {                        i++;xun=1;                    }                }                if (ans>da) da=ans;            }            else            {                xun=1;                while (xun)                {                    hh=kk[i].hao/2;                    ans+=pp[hh].b-pp[hh].a;xun=0;                    if (i!=lp-1&&kk[i+1].shu==kk[i].shu&&kk[i+1].hao%2==kk[i].hao%2)                    {                        i++;xun=1;                    }                }                if (ans>da) da=ans;            }        }        printf("%I64d\n",da);    }    return 0;}




0 0
原创粉丝点击