标签:evolution int worms forms input output Copy 33A
题意:
A. Worms Evolution
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are nforms of worms. Worms of these forms have lengths a1, a2, ..., an. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this.
Input
The first line contains integer n (3 ≤ n ≤ 100) — amount of worm's forms. The second line contains n space-separated integers ai(1 ≤ ai ≤ 1000) — lengths of worms of each form.
Output
Output 3 distinct integers i j k (1 ≤ i, j, k ≤ n) — such indexes of worm's forms that ai = aj + ak. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that aj = ak.
Examples
input
Copy
5 1 2 3 5 7
output
Copy
3 2 1
input
Copy
5 1 8 1 5 1
output
Copy
-1
解析:
输入n个数字,判断数组里面是否存在两个数字相加等于数组里面的另外的一个数字并且返回其下标
代码:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
int a[1000];
cin>>n;
if (n>=3&&n<=100)
{
for (int x=1; x<=n; x++)
{
cin>>a[x];
}
for (int x=1; x<=n; x++)
{
for (int y=1; y<=n; y++)
{
for (int z=1;z<=n ; z++)
{
if (a[z]==a[y]+a[x]&&x!=y&&x!=z&&z!=y)
{
cout<<z<<" "<<y<<" "<<x;
return 0;
}
}
}
}
cout<<-1;
}
return 0;
}
标签:evolution,int,worms,forms,input,output,Copy,33A 来源: https://blog.csdn.net/m0_51646205/article/details/118812746
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。