• pipioj 1028: 可乐(贪心)


    http://www.pipioj.online/problem.php?id=1028

     1 #define IO std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
     2 #define bug(x) cout<<#x<<" is "<<x<<endl
     3 #include <bits/stdc++.h>
     4 #define iter ::iterator
     5 using namespace  std;
     6 typedef long long ll;
     7 typedef pair<int,ll>P;
     8 #define pb push_back
     9 #define mk make_pair
    10 #define se second
    11 #define fi first
    12 #define rs o*2+1
    13 #define ls o*2
    14 const ll mod=1e9+7;
    15 const int N=2e5+5;
    16 int T,n,k;
    17  
    18 ll a[35],v[35],res[35];
    19  
    20 ll L;
    21  
    22 struct node{
    23     ll x;
    24     int id;
    25 }b[35];
    26  
    27 bool cmp(node p,node q){
    28     return p.x<q.x;
    29 }
    30  
    31 int main(){
    32     IO;
    33     while(cin>>n>>L){
    34         for(int i=1;i<=n;i++)cin>>a[i],v[i]=(1<<(i-1)),res[i]=0;
    35  
    36         ll h=1;
    37         for(int i=n;i>=1;i--){
    38             b[i].id=i;
    39             b[i].x=a[i];
    40             b[i].x*=h;
    41             h*=2;
    42         }
    43  
    44         sort(b+1,b+1+n,cmp);
    45         ll ans=0,res=1e18;
    46         for(int i=1;i<=n;i++){
    47             if(L>=v[b[i].id]){
    48                 ll x=L/v[b[i].id];
    49                 ans+=x*a[b[i].id];
    50                 L-=x*v[b[i].id];
    51             }
    52             if(!L)break;
    53             res=min(res,ans+a[b[i].id]);
    54         }
    55         ans=min(ans,res);
    56         cout<<ans<<endl;
    57     }
    58 }
  • 相关阅读:
    计算机通信网
    程序员面试——数学和概率
    位移枚举
    OC中的宏定义
    配置Xcode的Device Orientation、AppIcon、LaunchImage
    Xcode中的Project和Target
    NSObject
    CG
    UICollectionViewLayout
    UICollectionView
  • 原文地址:https://www.cnblogs.com/ccsu-kid/p/14503383.html
Copyright © 2020-2023  润新知