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

【题意】

如何花最少的钱买最多的纪念品?首要满足纪念品尽可能多,纪念品数量一样花钱要最少,输出纪念品数量以及最少花费。

纪念品的价钱是这么定义的:,其中a是基价,k是总共要买的纪念品数量,x是纪念品的index。

题目给出各个纪念品的基价a(当然,x也随之确定)

【思路】

二分纪念品数量,判断是否满足题意直接贪心,O(n)算出每个纪念品的价钱,O(nlogn)排序,选出最小的mid个;

二分时间复杂度O(n).

所以总的时间复杂度是O(nlogn^2),1000 00刚好满足

【Accepted】

 #include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <ctime>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=1e5+;
struct souv
{
int base;
int x;
}a[maxn];
int n,S;
typedef long long ll;
int judge(int mid)
{
ll b[maxn];
for(int i=;i<=n;i++)
{
b[i]=(ll)a[i].base+(ll)a[i].x*(ll)mid;
}
sort(b+,b+n+);
ll sum=;
for(int i=;i<=mid;i++)
{
sum+=b[i];
}
if(sum<=(ll)S)
{
return sum;
}
return -; }
int main()
{
while(~scanf("%d%d",&n,&S))
{
for(int i=;i<=n;i++)
{
scanf("%d",&a[i].base);
a[i].x=i;
}
int l=;
int r=n;
int res=S;
while(l<=r)
{
int mid=(l+r)>>;
int ans=judge(mid);
if(ans!=-)
{
res=ans;
l=mid+;
}
else
{
r=mid-;
}
}
cout<<r<<" "<<res<<endl;
}
return ;
}

二分

【贪心+二分】codeforces C. Sagheer and Nubian Market的更多相关文章

  1. Codeforces J. Sagheer and Nubian Market(二分枚举)

    题目描述: Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes in ...

  2. CodeForces - 812C Sagheer and Nubian Market 二分

    On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friend ...

  3. CodeForce-812C Sagheer and Nubian Market(二分)

    Sagheer and Nubian Market CodeForces - 812C 题意:n个货物,每个货物基础价格是ai. 当你一共购买k个货物时,每个货物的价格为a[i]+k*i. 每个货物只 ...

  4. Codeforces Round #417 C. Sagheer and Nubian Market

    C. Sagheer and Nubian Market time limit per test  2 seconds memory limit per test  256 megabytes   O ...

  5. AC日记——Sagheer and Nubian Market codeforces 812c

    C - Sagheer and Nubian Market 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #defin ...

  6. CF812C Sagheer and Nubian Market

    CF812C Sagheer and Nubian Market 洛谷评测传送门 题目描述 On his trip to Luxor and Aswan, Sagheer went to a Nubi ...

  7. Codeforces812C Sagheer and Nubian Market 2017-06-02 20:39 153人阅读 评论(0) 收藏

    C. Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. Sagheer and Nubian Market CodeForces - 812C (二分)

    On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friend ...

  9. Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. neo4j(图数据库)是什么?

    不多说,直接上干货! 作为一款强健的,可伸缩的高性能数据库,Neo4j最适合完整的企业部署或者用于一个轻量级项目中完整服务器的一个子集存在. 它包括如下几个显著特点: 完整的ACID支持 高可用性 轻 ...

  2. laravel oauth2.0 文件上传报错

    报错信息:   "message": "Invalid stream or file provided for UploadedFile",    " ...

  3. TextView、EditText

    1.TextView     显示文本信息 常用属性: layout_width/height    控件的宽/高 width/heigth    文本区域的宽/高 text 显示的文本 textSi ...

  4. js深拷贝与浅拷贝的区别及实现

    1. 对于基本数据类型 其值在内存中占据着固定大小的空间,并被保存在栈内存中.当一个变量向另一个变量复制基本类型的值,会创建这个值的副本,并且我们不能给基本数据类型的值添加属性.其为深拷贝. 2. 对 ...

  5. Google的Java编程风格指南

    作者:Hawstein出处:http://hawstein.com/posts/google-java-style.html声明:本文采用以下协议进行授权: 自由转载-非商用-非衍生-保持署名|Cre ...

  6. Performance engineering introduction

    1.Performance Software performance is one of software quality attributes,  it  equal to efficiency w ...

  7. http://www.360doc.com/content/10/0928/12/11991_57014502.shtml

    http://www.360doc.com/content/10/0928/12/11991_57014502.shtml

  8. AI学习一:环境安装

    对于Python开发用户来讲,PIP安装软件包是家常便饭.但国外的源下载速度实在太慢,浪费时间.而且经常出现下载后安装出错问题.所以把PIP安装源替换成国内镜像,可以大幅提升下载速度,还可以提高安装成 ...

  9. LC.exe 已退出,代码为-1 问题解决

    最近一个c#工程,之前编译正常.后重装系统,安装DevExpress后,编译一直失败,并提示"4>C:\Windows\Microsoft.NET\Framework\v4.0.303 ...

  10. 使用JavaScript给对象修改注册监听器

    我们在开发一些大型前端项目时,会遇到这样一种情况,某个变量上有个字段.我们想知道是哪一段程序修改了这个变量上的字段.比如全局变量window上我们自定义了一个新字段_name,我们想知道到底有哪些程序 ...