Codeforces Round #121 (Div. 2)

http://codeforces.com/contest/192/problem/A

水题,这题枚举+二分可以解决,k1*(k1+1)  + k2*(k2+1) == 2* n  ,枚举k1( k1>=1 ,k1 <= sqrt(2*n)+1 )二分查找k2

http://codeforces.com/contest/192/problem/B

 dp水题

http://codeforces.com/contest/192/problem/C

看懂题意后就是就是dp水题,dp[start][end] 表示以字母start 开头的并且以end结尾的最大字符,每次加入一个字符,有两种选择 a1a2...an

  1) 把它连在以a1结尾的字符后

  2) 以a1为起点以an为终点更新 dp[a1][an]

ans=max(dp[i][i]);  i>=1,i<=n;

http://codeforces.com/contest/192/problem/D


这题看懂题意后也就是水题,就不解释了,贪心即可

#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;

typedef  __int64 ll;

struct Node
{
    ll cost;
    int id;       
    bool operator<(Node dd) const
    {
        return cost > dd.cost;     
    }
}a[500010];

int main(int argc, char *argv[])
{
    int n,k;
    ll b,tot;
    while(cin>>n>>k)
    {
         tot=0;           
         cin>>b;           
         for(int i=1;i<=n;i++)                
            cin>>a[i].cost,a[i].id=i;
         sort(a+1,a+n);  
         for(int i=1;i<=k;i++)
           tot+=a[i].cost;
         b-=tot;  
         int ans=n;
         if(b<0)
         {
              ll remain=b+a[k].cost;
              for(int i=k;i<n;i++)
                if(remain<a[i].cost&&ans>a[i].id)
                  ans=a[i].id;
              
         }
          cout<<ans<<endl;   
    }
   // system("PAUSE");
    return EXIT_SUCCESS;
}



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值