Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)

B - Journey Planning
思路:
找规律
当时想了很久想了个O(n^2)的dp,然后想如何优化,其实这些数减去他们下标的差值是一样的。
Ci+1-Ci=Bi+1-Bi
Ci+2-Ci+1=Bi+2-Bi+1
Ci+1-Bi+1=Ci-Bi构造同一个数组存放即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <map>
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll maxn = 1e6 + 5;
const int N = 2e5;

int b[maxn];
ll s[maxn];

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		s[b[i]-i+N]+=b[i];
	}
	cout<<*max_element(s,s+maxn);
	return 0;
}

C - Remove Adjacent
思路:
做题的时候没读清题意,每次只能删比较大的数,所以很简单,暴力模拟,从最大的数开始删,即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <map>
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll maxn = 1e6 + 5;

char ch[105];
vector<char>s;

int main(){
	int n;
	cin>>n>>ch;
	for(int i=0;i<n;i++){
		s.push_back(ch[i]);
	}
	for(int i='z';i>='a';i--){
		for(int j=0;j<s.size();j++){
			if(s[j]!=i) continue;
			if(s[j]==s[j-1]+1 || s[j]==s[j+1]+1){
				s.erase(s.begin()+j);
				j=max(-1,j-2);
			}
		}
	}
	cout<<n-s.size();
	return 0;
}

D - Navigation System
待补

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值