https://vjudge.net/problem/2198220/origin
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的更多相关文章
- https://vjudge.net/problem/2198221/origin
https://vjudge.net/problem/2198221/origin逆向思维,原题是人出来,我们处理成人进去,算出来每个人的曼哈顿距离,然后从大到小排序,距离长的先入.走的距离+这个人从 ...
- 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- ...
- https://vjudge.net/contest/321565#problem/C 超时代码
#include <iostream> #include <cstdio> #include <queue> #include <algorithm> ...
- LOJ [#115. 无源汇有上下界可行流](https://loj.ac/problem/115)
#115. 无源汇有上下界可行流 先扔个板子,上下界的东西一点点搞,写在奇怪的合集里面 Code: #include <cstdio> #include <cstring> # ...
- POJ 2516:Minimum Cost(最小费用流)
https://vjudge.net/problem/11079/origin 题意:有N个商店和M个供应商和K种物品,每个商店每种物品有一个需求数,每个供应商每种物品有一个供应量,供应商到商店之间的 ...
- UVa 10934 Dropping water balloons:dp(递推)
题目链接:https://vjudge.net/problem/27377/origin 题意: 有一栋n层高的楼,并给你k个水球.在一定高度及以上将水球扔下,水球会摔破:在这个高度以下扔,水球不会摔 ...
- 一道简单的dp题 --- Greenhouse Effect CodeForces - 269B
题目链接: https://vjudge.net/problem/36696/origin 题目大意: 要求从1到m升序排列,点可以随意移动,问最少需要移动多少次, 思路: 动态规划 可以推出转移方程 ...
- STL复习之 map & vector --- disney HDU 2142
题目链接: https://vjudge.net/problem/40913/origin 大致题意: 这是一道纯模拟题,不多说了. 思路: map模拟,vector辅助 其中用了map的函数: er ...
- 一道dfs和dp结合的好题 --- Longest Run on a SnowboardUVA-10285
题目链接: https://vjudge.net/problem/19213/origin 大致题意: 一个滑雪者想知道自己在固定高度的山坡中最多能滑的距离是多少. 思路: 首先想到的就是dfs,但是 ...
随机推荐
- selenium基础(鼠标和键盘事件)
selenium鼠标和键盘的操作事件 webdriver常见的几种操作方法 clear():清楚文本文字 send_keys(values):模拟按键输入,values是输入的内容 click():单 ...
- thinkphp3.2.3 nginx 连接mysql 报错 new PDO 异常
在 php.ini 里重新指定mysql.sock 路径 pdo_mysql.default_socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql ...
- Codeigniter 获取当前的控制器名称和方法名称
在Codeigniter 可以通过下面两个方法获取当前的控制器名称和方法名称 $this->router->fetch_class(); $this->router->fetc ...
- [记]Cordova安装插件选择插件版本
在项目中可以使用 cordova plugin add [PLUGIN_ID] 這个命令安装一个cordova插件,这个命令好像是安装插件的最新版本.当需要通过cordova下载这个插件一个特定的版本 ...
- xcart小数点位数
xcart小数点的位数默认是2位,有时候需要根据需要更改位数:一开始以为把数据库中的数据类型的位数更改过后,就能生效,结果发现xcart在程序中作了限制,只能是2位.那么只能通过更改程序的方式来更改了 ...
- $.ajax()方法和$.get()方法使用小结
一. 使用JQuery的$.get()方法实现异步请求 1. 编写JSP <!DOCTYPE html> <html lang="en"> <head ...
- BZOJ2226:[SPOJ5971]LCMSum
Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes t ...
- php链表笔记:合并两个有序链表
<?php /** * Created by PhpStorm. * User: huizhou * Date: 2018/12/2 * Time: 15:29 */ /** * 合并两个有序链 ...
- NopCommerce3.9安装
除非另外说明,否则本分类所有博文的NopCommerce都基于3.9版本. 用vs2015打开,其他版本的vs没试过. 首先打开解决方案,然后设置Nop.web为启动项目. 启动项目,项目即可自动编译 ...
- vue后台管理项目中菜单栏切换的三种方法
第一种方法:vue嵌套路由(二) <el-menu :default-active="defaultActive" style="min-height: 100%; ...