
正文
Codeforces Round #381 (Div. 2) 复习倍增//
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
刷了这套题 感触良多
我想 感觉上的差一点就是差很多吧 。
每次都差一点 就是差很多了。。。
不能气馁。。要更加努力去填补那一点点。 老天不是在造物弄人,而是希望你用更好的自己去迎接自己。
A. Alyona and copybooks
有n本书 还需要买k本使得(n+k)%4==0
有三种 一本 a元 两本 b元 三本 c元的 不能分开卖
问至少花多少
枚举一下即可 。。。 我居然一开始搞了个dp记录买1-4本的最优策略....还wa了....
#include <stdio.h>
#include <iostream>
#include <algorithm>
//#include <>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 2e5+;
ll v[];
int main()
{
int n;
cin>>n;
for(int i=;i<=;i++)
cin>>v[i];
ll ans = LONG_LONG_MAX;
for(int i=;i<=;i++)
for(int j=;j<=;j++)
for(int k=;k<=;k++)
{
if((n+i+j*+k*)%==)
{
ans = min(ans,i*v[]+j*v[]+k*v[]);
}
}
cout<<ans<<endl;
return ;
}
AC代码
B. Alyona and flowers
给你m个区间 问选任意的区间使得和最大
发现区间和为负不要选就好
#include <stdio.h>
#include <iostream>
#include <algorithm>
//#include <>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 2e5+;
ll v[];
int main()
{
int n,k;
cin>>n>>k;
for(int i=;i<=n;i++)
{ cin>>v[i];
v[i]+=v[i-];
}
ll ans = ;
while(k--)
{
int x;int y;
cin>>x>>y;
ll val = v[y] - v[x-];
if(val>) ans+=val;
}
cout<<ans<<endl;
return ;
}
AC代码
C. Alyona and mex
给你长度为n的序列和m个区间,为区间中没出现过的最小的非负整数最大是多少。
那么区间最短的那个决定ans
接下来我们按照
[0,ans-1]这样循环填充n个位置。这样的话在任意的区间内都有[0,ans-1]
这个很机智啊。。。。
#include <stdio.h>
#include <iostream>
#include <algorithm>
//#include <>
#include <vector>
using namespace std;
typedef long long ll; int main()
{
int n,k;
cin>>n>>k;
int ans = INT_MAX;
for(int i=;i<k;i++)
{
int x;int y;
cin>>x>>y;
if((y-x)<ans)
{
ans = y-x;
}
}
ans++;
cout<<ans<<endl;
for(int i=;i<n;i++)
{
printf("%d ",i%ans);
}
return ;
}
AC代码
D.倍增LCA
想一想 MK一下







