Sagheer and Nubian Market

CodeForces - 812C

题意:n个货物,每个货物基础价格是ai。
当你一共购买k个货物时,每个货物的价格为a[i]+k*i。
每个货物只能购买一次。给你s金币,问你最多可以购买多少个货物,这些货物的最小花费。
题解:
直接二分(1~n)购买数量,每次二分都对每个货物计算价格a[i]+mid*i。
结构体对价格排序,mid个货物总价格大于s的时候break并往小二分,否则往大二分。
数据类型开long long。
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
// #define _ ios::sync_with_stdio(false)
// #define cin.tie(0)
#define PI 3.141592653
using namespace std;
// #define rep(i,x,y) for(int i=x;i<y;i++)
const int INF = 10000000;
const int MAXN = 200050;
typedef long long ll; struct st
{
ll id;
ll val;
ll sum;
}a[100050];
bool cmp(st a,st b)
{
return a.sum<b.sum;
}
int main()
{
int n;
ll s;
cin>>n>>s;
for(int i=1;i<=n;i++)
{
cin>>a[i].val;
a[i].id=i;
}
int result=0;
ll t=0;
int low=0,high=n;
while(low<=high)
{
int mid=(low+high)/2;
for(int i=1;i<=n;i++)
{
a[i].sum=a[i].val+a[i].id*mid;
}
ll sm=0;
sort(a+1,a+1+n,cmp);
for(int i=1;i<=mid;i++)
{
sm+=a[i].sum;
if(sm>s)
{break;}
}
if(sm<=s)
{
result=mid;
t=sm;
low=mid+1;
}
else
high=mid-1;
}
cout<<result<<" "<<t<<endl;
return 0;
}

CodeForce-812C Sagheer and Nubian Market(二分)的更多相关文章

  1. 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 ...

  2. #417 Div2 Problem C Sagheer and Nubian Market (二分 && std::accumulate)

    题目链接 : http://codeforces.com/problemset/problem/812/C 题意 : 给你 n 件物品和你拥有的钱 S, 接下来给出这 n 件物品的价格, 这些物品的价 ...

  3. CF812C Sagheer and Nubian Market 二分+贪心

    模拟赛给他们出T1好了~ code: #include <bits/stdc++.h> #define ll long long #define N 100006 #define setI ...

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

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

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

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

  6. 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 ...

  7. 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 ...

  8. CF812C Sagheer and Nubian Market

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

  9. 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 ...

随机推荐

  1. 遗传算法 TSP(Python代码)

    该代码是本人根据B站up主侯昶曦的代码所修改的. 原代码github地址:https://github.com/Houchangxi/heuristic-algorithm/blob/master/T ...

  2. Docker小白到实战之常用命令演示,通俗易懂

    前言 上一篇大概认识了Docker,主要是从概念.架构.优点及流程方面进行阐述,并进行安装和体验: 接下来就开始进行实操学习,在演示过程中会针对关键的知识点进行归纳和总结,这里先从常用命令说起,来吧, ...

  3. C#给线程传递数据

    目录 0. 前情说明 1. ParameterizedThreadStart类型的委托 2. 使用自定义类 3. 使用Lambda表达式 4. 参考以及文中源代码下载 shanzm-2021年8月24 ...

  4. xml的约束

    一.DTD约束xml 1.约束介绍 由于xml的标签由用户自己定义,因此在开发的时候,每个人都可以根据自己的需求来定义xml标签,这样导致项目中的xml难以维护,因此需要使用一定的规范机制来约束xml ...

  5. C++基于ATL工程编写ActiveX控件步骤

    参考网址: https://blog.csdn.net/whui19890911/article/details/8896554 开发环境:VS2010 开发工程:C++ATL项目 开发目的:创建Ac ...

  6. 使用git下载码云仓库文件步骤总结

    从码云下载文件的两种方式(私服时) 1.让私服管理者复制链接,然后你加入私服: 2.生成公钥,让私服管理者添加你的公钥. 在eclipse中找到git,输入自己的登录账号和密码,下载文件到本地仓库,然 ...

  7. log4j.properties配置文件及详解

    log4j配置文件有三个主要的组件:Logger,Appender和Layout,分别为日志类型,日志输出目的地,日志输出格式. 1. 配置日志级别及appenderName log4j.rootLo ...

  8. Struts中整合的强大Ognl学习(一)

    测试使用了一个JavaBean的User,User中的Address单独封装再形成了一个JavaBean: 为了测试静态方法和静态变量调用,写了一个Util方法: 因为测试Ognl功能过多所以直接使用 ...

  9. C++:继承

    共有继承(public),私有继承(private),保护继承(protected): 1.public继承: 基类成员类型 作为派生类成员 在派生类中是否可见 对派生类对象的可见性 public p ...

  10. python进阶(20) 正则表达式的超详细使用

    正则表达式   正则表达式(Regular Expression,在代码中常简写为regex. regexp.RE 或re)是预先定义好的一个"规则字符率",通过这个"规 ...