玲珑acm 倍增
来源:互联网 发布:人工智能对社会 编辑:程序博客网 时间:2024/06/03 22:59
地址:http://www.ifrog.cc/acm/problem/1112
官方题解很详细:
这里就不做过多的解释了,注意一下long long就可以了和倍增超过最大限度就好了
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;#define LL long longLL arr[300005];LL v[300005];LL tarr[300005];bool cmp(LL a, LL b){return a < b;}bool isFuck(int s, int e,LL k){int tail = 0;for (int i = s;i <= e;i++)tarr[++tail] = arr[i];sort(tarr+1, tarr + tail+1, cmp);LL ans = 0;for (int i = 1;i <= tail;i++){ans += tarr[i] * v[i];if (ans > k){return true;}}return false;}int _find(int s,int l, int r, LL k){while (l <= r){int mid = (l + r) / 2;if (isFuck(s, mid,k) == false)l = mid + 1;else{r = mid - 1;}}return l;}int anspos[300005];int main(){int q;LL k;while (scanf("%d%lld", &q, &k) != EOF){for(int i = 0;i<=q;i++)anspos[i] = 0;for (int i = 1;i <= q;i++){scanf("%lld", &arr[i]);}for (int i = 1;i <= q;i++)scanf("%lld", &v[i]);int ans = 0;int pos = 1;int anstail = 0;while (pos <= q){int tpos = 1;int lastpos = 0;while (tpos+pos <= q && isFuck(pos, pos+tpos, k) == false){lastpos = tpos;tpos *= 2;}if (tpos+pos > q)tpos = q-pos;//cout << lastpos << "+" << tpos << endl;int bigpos = _find(pos, pos+lastpos, pos+tpos, k);//cout << pos << "-" << bigpos << "-" << tpos << "-" << lastpos << endl;if (bigpos <= q){pos = bigpos + 1;ans++;anspos[bigpos] = ans;}else{break;}}for(int i = 1;i<=q;i++){anspos[i] = max(anspos[i-1],anspos[i]);if(i!=1)printf(" ");printf("%d",anspos[i]);}printf("\n");}return 0;}
0 0
- 玲珑acm 倍增
- 二分+倍增思想 “玲珑杯”ACM比赛 Round #13/B
- “玲珑杯”ACM比赛 Round #13 B -- 我也不是B,倍增+二分!
- 玲珑杯-1112 (倍增+二分)
- 【玲珑杯 Round#13 B】 【倍增+二分】
- [玲珑杯#Round8] XJT Love Strings KMP+树上倍增
- 倍增二分——玲珑学院OJ #1112
- 玲珑学院-ACM比赛1014 - Absolute Defeat
- “玲珑杯”ACM比赛 Round #4
- 玲珑ACM 1064 I am Two
- 玲珑杯”ACM比赛 Round #5
- “玲珑杯”ACM比赛 Round #7
- “玲珑杯”ACM比赛 Round #7
- “玲珑杯”ACM比赛 Round #11 " ---1097
- “玲珑杯”ACM比赛 Round #11 D
- “玲珑杯”ACM比赛 Round #11
- “玲珑杯”ACM比赛 Round #12【dp】
- “玲珑杯”ACM比赛 Round #13
- librtmp & rtmpdump开源项目github
- 字符判断
- ajax的异步加载和return的失效
- 算法提高 7-2求arccos值
- MFC找不到控件ID的原因
- 玲珑acm 倍增
- android混淆
- Discuz!字符串裁剪函数cutstr介绍
- 路漫漫其修远兮,吾将上下而求索
- JMeter使用中遇到的问题该如何解决?
- 用navicat premium连接数据库遇到的问题
- android开发 NDK 编译和使用静态库、动态库
- JDK中设计模式
- GUI_如何设置窗体居中的代码