Codeforces 812 C Sagheer and Nubian Market
来源:互联网 发布:建军大业影评 知乎 编辑:程序博客网 时间:2024/05/24 04:42
题目链接:http://codeforces.com/contest/812/problem/C
题意:他给你n个数字,给你一个最多能花的代价,让你求最多能买多少的东西,只是他每个物品代价和要买多少个物品有关系(如买k件物品,则代价为 Axj + xj·k )
题解:第一个想法就是二分,二分每次要买的东西个数,每次在按那个规则排序就能写出来了(PS居然是因为精度问题一直在wa,最后才发现)
#include <iostream>#include <cstring>#include <string>#include <vector>#include <queue>#include <map>#include <set>#include <algorithm>#define N 100010#define inf 0x3f3f3f3f#define LL long longusing namespace std;LL mid;LL cnt;LL n, m;struct node { LL id, num;}a[N];bool cmp(node aa, node b) { return aa.id*mid + aa.num < b.id*mid + b.num;}bool solve() { LL sum = 0; sort(a, a + n, cmp); for (int i = 0; i < mid; i++) { sum += a[i].id*mid + a[i].num; } if (sum <= m) { cnt = sum; return true; } return false;}int main() { cin.sync_with_stdio(false); while (cin >> n >> m) { for (int i = 0; i < n; i++) { cin >> a[i].num; a[i].id = i + 1; } cnt = 0; LL l = 0; LL ans = 0; LL r = n; while (l <= r) { mid = (l + r) >> 1; if (solve()) { ans = mid; l = mid + 1; } else { r = mid - 1; } } cout << ans << " " << cnt << endl; } return 0;}
阅读全文
2 0
- Codeforces 812C-Sagheer and Nubian Market
- Codeforces 812 C Sagheer and Nubian Market
- Codeforces 812C Sagheer and Nubian Market
- codeforces 812C Sagheer and Nubian Market
- Codeforces 812C Sagheer and Nubian Market[二分]
- Codeforces 812C Sagheer and Nubian Market【二分】水题
- codeforces 812 C. Sagheer and Nubian Market(二分答案)
- 【Codeforces 812 C. Sagheer and Nubian Market】+ 二分
- codeforces 812C Sagheer and Nubian Market (二分)
- C. Sagheer and Nubian Market
- Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market
- Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market
- Sagheer and Nubian Market
- Sagheer and Nubian Market
- Sagheer and Nubian Market
- codeforces 812C——Sagheer and Nubian Market(二分)
- CF# 812 C. Sagheer and Nubian Market(二分)
- Codeforces812C Sagheer and Nubian Market
- Java.lang.ExceptionInInitializerError 错误
- Jenkins全流程搭建
- Python学习笔记01
- 如何解决testng执行用例失败自动重跑问题
- LeetCode 71. Simplify Path
- Codeforces 812 C Sagheer and Nubian Market
- Linux Ubuntu 快速实现Mycat分片管理
- 【贪心策略】USACO 越野跑
- Elasticsearch 5 Ik+pinyin分词配置详解
- Lintcode——整数排序
- 责任链模式(Chain of Responsibility Pattern)
- eclipse导出项目(war包),部署到tomcat,测试实例
- Ubuntu16.04系统中文件名乱码解决方法
- php含有闭包特殊使用