【codeforces 812C】Sagheer and Nubian Market
【题目链接】:http://codeforces.com/contest/812/problem/C
【题意】
给你n个物品;
你可以选购k个物品;则
每个物品有一个基础价值;
然后还有一个附加价值;
即为k*i;
这里i是这个物品的下标;(1..n中的某个整数);
然后你有预算S;
问你最多能买多少个物品ans;
并求出买ans个物品的最小花费;
【题解】
二分买的物品数量k;
然后就能获取出每个物品的价格了;
即a[i]+i*k;
放到b数组里面;
升序排;
然后选取前k个;
看看超不超预算;
不超就记录答案,并让物品数量变大;
否则变小;
貌似在算的时候会爆int;
【Number Of WA】
1
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5+100;
LL n,s,tans;
LL a[N],b[N];
bool ok(LL k){
for (LL i = 1;i <= n;i++){
b[i] = a[i]+i*k;
}
sort(b+1,b+1+n);
LL temp = 0;
rep1(i,1,k){
temp+=b[i];
if (temp>s) return false;
}
tans = temp;
return true;
}
int main(){
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> n >> s;
rep1(i,1,n){
cin >> a[i];
}
int l = 0,r = n,ans = 0;
while (l <= r){
int mid = (l+r)>>1;
if (ok(mid)){
ans = mid;
l = mid+1;
}
else
r = mid-1;
}
cout << ans <<' '<<tans<<endl;
return 0;
}
【codeforces 812C】Sagheer and Nubian Market的更多相关文章
- 【codeforces 812B】Sagheer, the Hausmeister
[题目链接]:http://codeforces.com/contest/812/problem/B [题意] 一个老大爷在一楼; 然后他有n楼的灯要关(最多n楼); 每楼有m个房间; 给出每个房间的 ...
- 【codeforces 812A】Sagheer and Crossroads
[题目链接]:http://codeforces.com/contest/812/problem/A [题意] 有一个小箭头指的那个地方; 指的就是人行道路; 然后p[i]指的就是那4个人行道是不是绿 ...
- AC日记——Sagheer and Nubian Market codeforces 812c
C - Sagheer and Nubian Market 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #defin ...
- 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 ...
- Codeforces J. Sagheer and Nubian Market(二分枚举)
题目描述: Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes in ...
- CodeForce-812C Sagheer and Nubian Market(二分)
Sagheer and Nubian Market CodeForces - 812C 题意:n个货物,每个货物基础价格是ai. 当你一共购买k个货物时,每个货物的价格为a[i]+k*i. 每个货物只 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 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 ...
- CF812C Sagheer and Nubian Market
CF812C Sagheer and Nubian Market 洛谷评测传送门 题目描述 On his trip to Luxor and Aswan, Sagheer went to a Nubi ...
随机推荐
- OA项目知识总结2
BaseAction的抽取 项目中的每个实体类都对应一个action 每个action都都要继承ActionSupport类 已以及实现ModelDriver接口 并且需要注入service 虽然 ...
- ST Nucleo mbed套件开发 一 MBED环境使用 以Nucleo-F401为例 (二)
MBED环境.使用起来总是那么的别扭可能很多人不习惯用在线编程器,大多数做ST32开发的都比較喜欢KEIL或者IAR,有没有什么好的方法呢.我们能够本地编译MBEDproject, 答案是肯定了.下来 ...
- 继续过Hard题目.0209
http://www.cnblogs.com/charlesblc/p/6372971.html 继续过Hard模式的题目吧. # Title Editorial Acceptance Diffi ...
- 使用 from import方法导入Python模块
比如我们导入一个数学计算的模块 math: >>> import math>>> print math<module 'math' (built-in)> ...
- Fatal error: Incompatible file format: The encoded file has format major ID 1...解决方式
申请好域名和空间后.将站点源代码上传到空间,解析好域名后.在地址栏输入域名出现以下错误: Fatal error: Incompatible file format: The encoded file ...
- sql server 数据库展开变慢
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/99bbcb47-d4b5-4ec0-9e91-b1a23a655844/ssms-2 ...
- Javascript中的with用法
1.看例子 <script language="javascript"> function Lakers() { this.name = "kobe brya ...
- 18. 4Sum[M]四数之和
题目 Given an array nums of n integers and an integer target, are there elements a, b, c and d in nums ...
- ios中去除tableView的分割线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- 关于HTML与CSS与class
在web前端开发中接触的一直是html.css.javascript. 在这个过程中,经常使用的是html中的span.div元素以及css的选择器. 为了方便查找在这里将这些内容的基础知识记录下来. ...