Codeforces 650B Image Preview 【二分】
2016-03-09 14:28
253 查看
题目链接:Codeforces 650B Image Preview
题意:给你n张图片,每次可以花费时间a移动到临近的图片。图片的位置分w和h,w的需要花时间b翻转位置。看一张照片花时间1,问你在时间t的前提下最多可以看多少照片。
思路:二分,对于长度o,分o种情况讨论,看是否满足<=t。
AC代码:
题意:给你n张图片,每次可以花费时间a移动到临近的图片。图片的位置分w和h,w的需要花时间b翻转位置。看一张照片花时间1,问你在时间t的前提下最多可以看多少照片。
思路:二分,对于长度o,分o种情况讨论,看是否满足<=t。
AC代码:
#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 second using 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 - 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; }
相关文章推荐
- 怎样显示MYSQL表的信息
- 语音增强算法研究系列(四):非平稳噪声消除
- 前端基础学习-css基础笔记
- online_judge_1513
- Java源码阅读之TreeMap
- 《iOS Human Interface Guidelines》——Scope Bar
- PopupWindow的使用和分析 弹出框的一种
- bzoj4385 Wilcze doły
- Git:错误:error:src refspec master does not match any
- Codeforces 650A Watchmen 【数学 + 二分】
- DP啊啊啊啊啊啊啊啊!
- opencv mat元素的遍历
- 人机对决 | 无论比赛结果如何,都是人类的胜利
- 236. Lowest Common Ancestor of a Binary Tree
- 程序猿如何应对工作中的烦恼
- 1002-切面条
- Java ConcurrentModificationException异常原因和解决方法
- 【SQL 问题】试用版SQL Server 2008 R2 提示评估期已过,数据库不能访问解决办法
- 【转】Xcode真机调试初体验
- vs2010的VCVARS32.BAT所在位置