796. 表面积

796. 表面积

题面统计数据1 个讨论

单点时限: 1.0 sec

内存限制: 512 MB

在 n 个圆柱体中挑选 m 个,按照半径从大到小圆心对齐叠在一起放在地面上(最大的一个在最下面),计算可能的最大可视表面积。

输入格式

第 1 行:整数 n(1≤n≤1000)和 m(1≤m≤n),一个空格分隔。

第 2,…,n+1 行:每个圆柱体的半径 R cm与高度 H cm(1≤R,H≤106),一个空格分隔。

输出格式

一行中输出x。表示可能的最大表面积为 x 乘以圆周率的 cm2。

样例

input

2 1
100 20
200 10

output

44000

input

3 2
100 10
100 10
100 10

output

14000

input

4 2
9 3
7 1
10 1
8 4

output

199

 

提示:

按侧面积进行排序,从大到小,然后选择最大的底面积作为底面圆柱。

 

#include<iostream>
#include<cstdio>
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<cctype>
#include<set>
#include<queue>
#include<bitset>
#include<stack>
using namespace std;
struct yuan
{
    long long r,h;
    long long d,c;
}a[1100];
long long cmp(yuan a,yuan b)
{
    return a.c>b.c;
}
int main()
{
    long long n,m,maxn=-1;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].r>>a[i].h;
        a[i].d=a[i].r*a[i].r;
        a[i].c=2*a[i].r*a[i].h;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i++)
    {
        long long ans=a[i].c+a[i].d;
        int count1=1;
        for(int j=1;j<=n&&count1<m;j++)
        {
            if(i==j||a[i].r<a[j].r)    continue;
            ans+=a[j].c;
            count1++;
        }
        maxn=max(maxn,ans);
    }
    cout<<maxn<<endl;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值