hdoj5328【尺取】
现在在队内赛(灰常艾斯比的队内赛),还是来写篇题解开心一下,23333.
题意:
就是问你找出一个最长的等比数列或者等差数列
思路:
一个等差的尺取,一个等比的尺取。2333,就这么过了,具体自己写吧。还是很容易实现的,注意数组要开1e6…还有long long….后面要做乘法。
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
typedef __int64 LL;
const int N=1e6+10;
LL a[N];
int n;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
if(n==1)
{
puts("1");
continue;
}
int sum1;
int sum2,temp;
int s,t;
LL x1,x2;
temp=1;
sum1=1;
t=2;
for(s=1;s<n;s++)
{
x1=a[t]-a[s];
while(x1==(a[t+1]-a[t])&&t+1<=n)
{
temp=t-s+2;
t++;
}
s=t-1;
t=t+1;
sum1=max(sum1,temp);
}
temp=sum2=2;
t=2;
for(s=1;s<n;s++)
{
while((a[t+1]*a[t-1])==(a[t]*a[t])&&t+1<=n)
{
temp=t-s+2;
t++;
}
s=t-1;
t=t+1;
sum2=max(sum2,temp);
}
printf("%d\n",max(sum1,sum2));
}
}
/*
10
1 2 3 4 6 8 10 12 14 16
13
1 2 3 4 6 1 3 1 8 10 12 14 16
*/
hdoj5328【尺取】的更多相关文章
- Gym 100703I---Endeavor for perfection(尺取)
题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...
- NOJ 1072 The longest same color grid(尺取)
Problem 1072: The longest same color grid Time Limits: 1000 MS Memory Limits: 65536 KB 64-bit in ...
- hdu 4123 Bob’s Race 树的直径+rmq+尺取
Bob’s Race Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- poj2566尺取变形
Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...
- poj2100还是尺取
King George has recently decided that he would like to have a new design for the royal graveyard. Th ...
- hdu 6231 -- K-th Number(二分+尺取)
题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an ...
- Codeforces 939E Maximize! (三分 || 尺取)
<题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...
- cf1121d 尺取
尺取,写起来有点麻烦 枚举左端点,然后找到右端点,,使得区间[l,r]里各种颜色花朵的数量满足b数组中各种花朵的数量,然后再judge区间[l,r]截取出后能否可以供剩下的n-1个人做花环 /* 给定 ...
随机推荐
- iOS应用崩溃日志分析 iOS应用崩溃日志揭秘
转自:http://www.raywenderlich.com/zh-hans/30818/ios%E5%BA%94%E7%94%A8%E5%B4%A9%E6%BA%83%E6%97%A5%E5%BF ...
- 处理页面载入图片js(等比例压缩图片)
第一页面html <div class="admin">${answer.content}</div> <div class="admin ...
- HDU 1022 Train Problem I (数据结构 —— 栈)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
- linux 输入子系统(2) platform device
Input platform device 一般是在板级bsp注册了的资源. 以gpio-keys为例: #####################gpio_key.h############ ...
- H5新增表单属性
一.form属性 <form id="test"> <input type="text" placeholder="请输入合适的信息 ...
- spring MVC (学习笔记)
web.xml 相关配置 <?xml version="1.0" encoding="UTF-8"?><web-app xmlns=" ...
- 将异常(getStackTrace)转化成String
方法一: private static String getStackMsg(Exception e) { StringBuffer sb = new StringBuffer(); StackTra ...
- aapt2 错误
android.enableAapt2=false Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conf ...
- ruby require
require一般用来加载其它的类,如: #Ruby代码 : require 'dbi' require "rexml/document" 但是上面加载的是标准类库里面的文 ...
- codeforces 679e Bear and Bad Powers of 42
传送门:http://codeforces.com/contest/679/problem/E 题目意思很清晰,给你一个序列,要求你完成以下三个操作: 1.输出A[i] 2.将[a,b]区间的所有数字 ...