首页 技术 正文
技术 2022年11月15日
0 收藏 740 点赞 4,356 浏览 2699 个字

题目链接:https://atcoder.jp/contests/abc128/tasks/abc128_f

题目大意

  给定长度为 N 的序列$s_0, s_1, \dots, s_{N-1}$,现在要选取两个正整数 A 和 B,从$s_0$起跳,按照先往前跳 A 步,再往后跳 B 步的规则正好跳到$s_{N-1}$,每跳到一个地方,其所对应的元素值将会计入你的总分。有如下限制:

  1. 不能跳出序列。
  2. 同一个地方只能被跳到一次。

  请选取适当的 A 和 B,使得得分最大。

分析

  设跳 B 步这个行为进行了 k 次。  那么$s_{A-B}, s_{2*(A-B)}, \dots, s_{k*(A-B)}$为每次跳 B 步后所能到达的点。  那么$s_{N-1 – (A-B)}, s_{N-1 – 2*(A-B)}, \dots, s_{N-1 – k*(A-B)}$为每次跳 A 步后所能到达的点。  可以发现,以上两个序列是一一对应的,唯一变化的只有 A – B 和 k,并且跳 B 步这个行为进行了 k 次可从跳 B 步这个行为进行了 k – 1 次递推而来。  于是我们可以暴力枚举所有的 A – B 和 k,复杂度大概为$O(N*(1 + \frac{1}{2} + \frac{1}{3} + \dots + \frac{1}{N}))$,几乎是线性的。

代码如下

 #include <bits/stdc++.h>
using namespace std; #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin()) #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} inline int gc(){
static const int BUF = 1e7;
static char buf[BUF], *bg = buf + BUF, *ed = bg; if(bg == ed) fread(bg = buf, , BUF, stdin);
return *bg++;
} inline int ri(){
int x = , f = , c = gc();
for(; c<||c>; f = c=='-'?-:f, c=gc());
for(; c>&&c<; x = x* + c - , c=gc());
return x*f;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef pair< string, int > PSI;
typedef set< int > SI;
typedef vector< int > VI;
typedef vector< PII > VPII;
typedef map< int, int > MII;
typedef multimap< int, int > MMII;
typedef unordered_map< int, int > uMII;
typedef pair< LL, LL > PLL;
typedef vector< LL > VL;
typedef vector< VL > VVL;
typedef priority_queue< int > PQIMax;
typedef priority_queue< int, VI, greater< int > > PQIMin;
const double EPS = 1e-;
const LL inf = 0x7fffffff;
const LL infLL = 0x7fffffffffffffffLL;
const LL mod = 1e9 + ;
const int maxN = 1e5 + ;
const LL ONE = ;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555; int N, s[maxN];
LL ans; int main(){
INIT();
cin >> N;
Rep(i, N) cin >> s[i]; For(i, , N - ) { // 枚举 A - B
LL ret = ;
For(k, , (N - ) / i) {
LL tmp = N - - i * k;
if(tmp <= i || tmp % i == && tmp / i <= k) break;
ret += s[i * k] + s[tmp];
ans = max(ans, ret);
}
} cout << ans << endl;
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903