Codeforces round #321 (DIV. 2)

博客包含了Codeforces Round #321 分数赛第二组的五道题目解析,分别是:A题‘Kefa and First Steps’的非递减子序列问题;B题‘Kefa and Company’的双关键字数组最大和问题,采用排序和双指针方法解决;C题‘Kefa and Park’要求求解最短路径上连续1不超过m个的叶子节点数量,通过DFS解决;D题‘Kefa and Dishes’涉及状压DP解决选择节点以最大化权和的问题;E题‘Kefa and Watch’则需要处理字符串周期性和查询,利用动态区间Hash值和线段树来解答。
摘要由CSDN通过智能技术生成

题解链接:http://www.cygmasot.com/index.php/2015/09/23/codeforces_580/

链接

A:Kefa and First Steps

题意:the length of the maximum non-decreasing subsegment

直接搞,水题

#include <cstring> 
#include <iostream>  
#include <algorithm>  
#include <cstdio>  
#include <map>
#include <queue>
#include <set>
using namespace std;
template <class T>
inline bool rd(T &ret) {
	char c; int sgn;
	if (c = getchar(), c == EOF) return 0;
	while (c != '-' && (c<'0' || c>'9')) c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
	ret *= sgn;
	return 1;
}
template <class T>
inline void pt(T x) {
	if (x <0) {
		putchar('-');
		x = -x;
	}
	if (x>9) pt(x / 10);
	putchar(x % 10 + '0');
}  
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1e9;
const int N = 1e5+10;
int n; 
int a[N];
int main() {
	rd(n);
	for (int i = 1; i <= n; i++)rd(a[i]);
	int ans = 1;
	for (int i = 2, pre = 1; i <= n; i++) {
		if (a[i] >= a[i - 1]) {
			pre++;
		}
		else pre = 1;
		ans = max(ans, pre);
	}pt(ans);
	return 0;
}


B:Kefa and Company

题意:有一个双关键字的数组,共n个元素。常数d
选任意个使得选出的元素中 第一关键字(最大的-最小的)<d
并且使得第二关键字和最大。
问:最大的和是多少。
思路:
先排个序,然后two pointers搞搞,枚举左端点,右端点是单调的。

#inclu
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值