【五校联考5day1】序列

Description
 Fiugou想要在一个长度为N的序列A中找到不同位置的三个数,以这三个数为三边长来构成一个三角形。但是它希望在满足条件下,这三个数的位置尽量靠前。具体地,设这三个数的为Ai,Aj,Ak(i<j<k), Fiugou希望k尽量小;当k相等时,满足j尽量小;当k,j均相等时,满足i尽量小。
但是这个序列中的数可能会发生变化。所以Fiugou给出了M个操作,形式如下:
1 x y:将Ax改为y
2:查询最优的合法解,从小到大给出这三个数(而不是位置)。

Input
第一行一个整数N,代表序列的长度。
第二行有N个整数,代表初始序列。
第三行一个整数M,代表操作的个数。
接下来M行操作,两种操作格式如上所述。

Output
 共M行,每行三个数,从小到大给出。如果不存在,输出-1 -1 -1。

Sample Input
6
7 1 3 4 5 1
3
2
1 3 5
2

Sample Output
3 5 7
4 5 7

Data Constraint
对于10%的数据, N<=10, M<=5
对于30%的数据, N<=100, M<=25
对于50%的数据, N<=1000, M<=1000
对于100%的数据, N<=100000, M<=1000
对于100%的数据, 0<=Ai<=10^9, 1<=x<=N, 0<=y<=10^9

.
.
.
.
.
分析
然而这道题暴力即可过了
理由:
如果给你极限数据的话
1,1,2,3,5,8,13,21,34,55,89,144…
就多也就是50项(差不多,如果大于50,那肯定有解)
所以啊,要不就是50项没有找到,要不就是找到了,就这么简单。

枚举要先确定后面的再找前面的

.
.
.
.
.
程序:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int n,m,a[100100];

inline int read()
{
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}

bool check(int x,int y,int z)
{
	if (x>y) swap(x,y);
	if (y>z) swap(y,z);
	if (x>y) swap(x,y);
	if (x+y>z) 
	{
		printf("%d %d %d
",x,y,z);
		return true;	
	} else return false;
}

void work()
{
	for (int i=3;i<=n;i++)
		for (int j=2;j<=i-1;j++)
			for (int k=1;k<=j-1;k++)
				if (check(a[i],a[j],a[k])==true) return;
	printf("%d %d %d
",-1,-1,-1);
}


int main()
{
	n=read();
	for (int i=1;i<=n;i++)
	 	a[i]=read();
	m=read();
	while (m--)
	{
		int cz;
		cz=read();
		if (cz==2) work(); else
		{
			int x;
			x=read();
			a[x]=read();
		}
	}
	return 0;
}
原文地址:https://www.cnblogs.com/YYC-0304/p/10458936.html