Codeforces 779D String Game 【二分】
来源:互联网 发布:证券客户经理知乎 编辑:程序博客网 时间:2024/05/02 01:21
题目链接:http://codeforces.com/contest/779/problem/D
题意:给你两个字符串p和t,又给你一个排列 a,现在第 i 次你需要删除p字符串中的第a[i] 个字符,问最晚出现p是t的子串是在什么时候。。
这道题让我挺伤心的。。明明比赛的时候已经写出代码了。。还是晚了一步。。hhh。。
题解:
直接二分。。挺有趣的一道题,刚开始还束手无策。。TAT
代码:
#include <cstdio>#include <string>#include <iostream>using namespace std;const int size = 2e5+5;string a, b;int permu[size];inline void quick_IO() { ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); }bool Same(string p, string q) { // 判断 p 是否是 q 的子串 int cs = 0; for ( int i = 0; i < p.size(); i ++ ) { if(p[i] == '-') continue; if(p[i] == q[cs]) { cs ++; } if(cs == q.size()) return true; } return false;}bool check(int t, string te) { for ( int i = 0; i < t; i ++) te[permu[i]-1] = '-'; return Same(te, b);}int main() { // freopen("D3.in", "r", stdin); quick_IO(); cin >> a >> b; for ( int i = 0; i < a.size(); i ++ ) cin >> permu[i]; int left = 0, right = a.size()-1; int ans; while ( left <= right ) { int mid = (left+right)/2; // cout << left << " " << right << endl; if(check(mid, a)) { left = mid+1; ans = mid; } else right = mid-1; } cout << ans << endl; return 0;}
0 0
- Codeforces 779D String Game 二分
- Codeforces 779D String Game 【二分】
- CodeForces 779D String Game【二分答案】
- codeforces 778D. String Game (二分搜索)
- 【Codeforces-402D】-String Game (二分)
- 【codeforces 779D】String Game
- codeforces 779 D. String Game
- Codeforces Round #402 (Div. 2) D. String Game (二分)
- Codeforces Round #402 (Div. 2)D. String Game 二分
- codeforces 799 D String Game (二分答案)
- Codeforces Round #402 (div. 2)D. String Game(二分)
- Codeforces Round #402 (Div. 2)D. String Game【二分】
- Codeforces Round #402 (Div. 2)D. String Game【二分】
- Codeforces Round #402 (Div. 2) D. String Game(二分)
- Codeforces Round #402 (Div. 2) D.String Game 二分搜索
- (二分, 字符串)Codeforces Round #402 D. String Game
- D. String Game----二分答案
- CF 779D String Game 二分,贪心匹配字符串
- syslog-ng + syslogd + logrotate
- zurmo(三) exception 'CException' with message 'Failed to resolve Product.startdate to column'
- Rapidminer的基本操作
- 安卓开发:Activity之间的切换和传值
- 4-8 求m到n之和 (10分)
- Codeforces 779D String Game 【二分】
- Redis——安全设置&主从复制
- vector基本用法(转载)
- app测试总结(fiddler抓包之https)
- matcaffe 编译报错
- 外存中的对换区和文件区
- 位运算相关知识
- 4-9 简单输出整数 (10分)
- 过去两年中国有1.8万富豪移民到西方国家