https://vjudge.net/problem/2198220/origin
枚举等差数列第一个和第二个,然后二分确定数列后面是否存在,复杂度比较玄学,卡过了。

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 5010
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
int n;
int a[N],ans,d,now,num;
void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main(){
in(n);
For(i,,n)
in(a[i]);
sort(a+,a+n+);
ans=;
For(i,,n-ans)
For(j,i+,n-ans+){
d=a[j]-a[i];
now=;
num=a[j];
while(){
num+=d;
if(binary_search(a+,a+n+,num))
now++;
else{
ans=max(ans,now);
break;
}
}
}
o(ans);
return ;
}

也可以dp做,f[j][i]=max(f[j][i],f[i][pre]+1);
f[j][i]表示j是等差数列最后一个下标,i是倒数第二个下标

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 5010
#define For(i,a,b) for(int i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
int n;
int a[N],ans,d,now,num,pre,f[N][N];
void in(int &x){
int y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(int x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main(){
in(n);
For(i,,n)
in(a[i]);
sort(a+,a+n+);
ans=;
For(i,,n)
For(j,,n)
f[i][j]=;
For(i,,n){
pre=i-;
For(j,i+,n){
while(pre>&&a[j]-a[i]>a[i]-a[pre]) pre--;
if(!pre) break;
if(pre>&&a[j]-a[i]==a[i]-a[pre])
f[j][i]=max(f[j][i],f[i][pre]+);
ans=max(ans,f[j][i]);
}
}
o(ans);
return ;
}

https://vjudge.net/problem/2198220/origin的更多相关文章

  1. https://vjudge.net/problem/2198221/origin

    https://vjudge.net/problem/2198221/origin逆向思维,原题是人出来,我们处理成人进去,算出来每个人的曼哈顿距离,然后从大到小排序,距离长的先入.走的距离+这个人从 ...

  2. C# webkit 内核浏览器 访问https 网站 提示 Problem with the SSL CA cert (path? access rights?)

    C# webkit 内核浏览器 访问https 网站 提示 Problem with the SSL CA cert (path? access rights?) 解决方法: 陈凯文11112014- ...

  3. https://vjudge.net/contest/321565#problem/C 超时代码

    #include <iostream> #include <cstdio> #include <queue> #include <algorithm> ...

  4. LOJ [#115. 无源汇有上下界可行流](https://loj.ac/problem/115)

    #115. 无源汇有上下界可行流 先扔个板子,上下界的东西一点点搞,写在奇怪的合集里面 Code: #include <cstdio> #include <cstring> # ...

  5. POJ 2516:Minimum Cost(最小费用流)

    https://vjudge.net/problem/11079/origin 题意:有N个商店和M个供应商和K种物品,每个商店每种物品有一个需求数,每个供应商每种物品有一个供应量,供应商到商店之间的 ...

  6. UVa 10934 Dropping water balloons:dp(递推)

    题目链接:https://vjudge.net/problem/27377/origin 题意: 有一栋n层高的楼,并给你k个水球.在一定高度及以上将水球扔下,水球会摔破:在这个高度以下扔,水球不会摔 ...

  7. 一道简单的dp题 --- Greenhouse Effect CodeForces - 269B

    题目链接: https://vjudge.net/problem/36696/origin 题目大意: 要求从1到m升序排列,点可以随意移动,问最少需要移动多少次, 思路: 动态规划 可以推出转移方程 ...

  8. STL复习之 map & vector --- disney HDU 2142

    题目链接: https://vjudge.net/problem/40913/origin 大致题意: 这是一道纯模拟题,不多说了. 思路: map模拟,vector辅助 其中用了map的函数: er ...

  9. 一道dfs和dp结合的好题 --- Longest Run on a SnowboardUVA-10285

    题目链接: https://vjudge.net/problem/19213/origin 大致题意: 一个滑雪者想知道自己在固定高度的山坡中最多能滑的距离是多少. 思路: 首先想到的就是dfs,但是 ...

随机推荐

  1. 13-2-return

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. POJ3321Apple Tree

    Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 39566 Accepted: 11727 Descript ...

  3. sqllocaldb

    创建实例  sqllocaldb create v12.0 启动实例 sqllocaldb start v12.0

  4. 【JZOJ3397】【luoguP4556】雨天的尾巴

    description 深绘里一直很讨厌雨天. 灼热的天气穿透了前半个夏天,后来一场大雨和随之而来的洪水,浇灭了一切. 虽然深绘里家乡的小村落对洪水有着顽固的抵抗力,但也倒了几座老房子,几棵老树被连 ...

  5. 使用subprocessm模块管理进程

    subprocess被用来替换一些老的模块和函数,如:os.system.os.spawn*.os.popen*.popen2.*.commands.*. subprocess的目的就是启动一个新的进 ...

  6. Ubuntu usb设备端口号绑定

    1.将串口设备插入USB口,通过lsusb查看端口信息.例如: ID 1a86:7523 表示usb设备的ID(这个ID由芯片制造商设置,可以唯一表示该设备) 1a86 usb_device_desc ...

  7. MySQL:MySQL 存储过程

    ylbtech-MySQL:MySQL 存储过程 1.返回顶部 1. MySQL 存储过程 MySQL 5.0 版本开始支持存储过程. 存储过程(Stored Procedure)是一种在数据库中存储 ...

  8. 图解SQL的Join

    原文地址:http://coolshell.cn/articles/3463.html 对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的 ...

  9. “Error: Encountered an improper argument”的解决方法

    之前遇到过的问题,后来解决后再次遇到又忘记了, 这是keil 的bug 路径只要都是字母就可以了

  10. TKmybatis的框架介绍及使用方法

    最近项目使用了SpringBoot+TKMytis框架,期间遇到一些问题,顺便记一下. 一.框架配置 配置的话非常简单,我用的是SpringBoot,直接引入: <dependency> ...