Codeforces 650B Image Preview 【二分】
来源:互联网 发布:淘宝简约店招 编辑:程序博客网 时间:2024/06/04 18:56
题目链接:Codeforces 650B Image Preview
题意:给你
思路:二分,对于长度
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#define CLR(a, b) memset(a, (b), sizeof(a))#define fi first#define se secondusing namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 5*1e5+10;const int INF = 0x3f3f3f3f;void getmax(int &a, int b) {a = max(a, b); }void getmin(int &a, int b) {a = min(a, b); }char str[MAXN];int sum[MAXN];int n, a, b, t;int get(int x, int y) { return min((x-1)*a*2 + (n-y+1)*a, (n-y+1)*a*2 + (x-1)*a); // s -> x -> s -> y or s -> y -> s -> x}bool judge(int o){ for(int i = 1; i <= o; i++) { if(sum[i] + sum[n] - sum[n-o+i] + get(i, n-(o-i)+1) <= t) return true; } return false;}int main(){ cin >> n >> a >> b >> t; cin >> str + 1; sum[0] = 0; for(int i = 1; i <= n; i++) { int v; if(str[i] == 'h') v = 1; else v = b + 1; sum[i] = sum[i-1] + v; //cout << sum[i] << endl; } int l = 0, r = n; int ans = 0; while(r >= l) { int mid = (l + r) >> 1; if(judge(mid)) { ans = mid; l = mid + 1; } else r = mid - 1; } cout << ans << endl; return 0;}
0 0
- Codeforces 650B Image Preview 【二分】
- CodeForces 650 B.Image Preview(二分)
- 【1】【二分搜索】CodeForces 650B Image Preview
- Codeforces #345 div1 B. Image Preview 二分
- 二分 - CF 650B Image Preview
- Codeforces 651D:Image Preview 二分
- Codeforces 651D Image Preview【二分+枚举】
- Codeforces Round #345 (Div. 2) D. Image Preview【二分】
- Codeforces Round #345 (Div. 2)D Image Preview(二分)
- Codeforces 651D Image Preview【思维+二分+前缀后缀和】
- Codeforces 650B 二分
- Codeforces Round #345 (Div. 2) (D. Image Preview(二分))
- cf#345-D - Image Preview-二分
- CodeForces 650B(二分)
- 【20.35%】【codeforces 651D】Image Preview
- 【Codeforces Round 345 (Div 1) B】【暴力 双指针】Image Preview 看照片、阅读、移动、反转最多看照片数
- CodeForces 302B 二分
- CodeForces 600B 二分
- kafka安装和启动
- 【LeetCode】83. Remove Duplicates from Sorted List
- 一步一步分析新建App启动过程
- linux中shell变量$#,$@,$0,$1,$2的含义解释
- GDB调试手册
- Codeforces 650B Image Preview 【二分】
- Oracle中数据类型number(m,n)
- C语言模拟栈
- c/c++基础
- Magento使用手机号注册登录开发过程
- 代码复用 -- 组合和继承
- tableViewcell的左滑动显示删除置顶更多的效果
- 《how to write and publish a scientific paper》 Chapter 4
- Android开发中使用dos命令连接外接设备device运行android项目