A. Worms Evolution
来源:互联网 发布:mac 梦幻西游手游网页 编辑:程序博客网 时间:2024/05/17 21:41
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.
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 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.
5
1 2 3 5 7
3 2 1
5
1 8 1 5 1
-1
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 110;
int n , data[maxn];
int main() {
scanf( "%d" , &n );
for ( int i = 1 ; i <= n ; i++ )
scanf( "%d" , &data[i] );
for ( int i = 1 ; i <= n ; i++ )
for ( int j = 1 ; j <= n ; j++ )
for ( int k = 1 ; k <= n ; k++ )
if ( i != j && i != k && j != k && data[i] == data[j] + data[k] ) {
printf( "%d %d %d\n" , i , j , k );
return 0;
}
printf( "-1\n" );
return 0;
}
- A. Worms Evolution
- 【水搜索】#31 A. Worms Evolution
- <cf>Worms Evolution
- Worms
- The Evolution of a Programmer
- The Evolution of a Programmer
- The Evolution of a Programmer
- The Evolution of a Programmer
- The Evolution of a Programmer
- CF 271 A Keyboard B Worms C Captain Marmot
- evolution
- evolution
- evolution
- evolution
- The Evolution of a Software Engineer
- HDU4404 Worms
- B. Worms
- B. Worms
- A. Almost Prime
- A. Next Test
- Oracle内置表二
- A. Spit Problem
- A. Accounting
- A. Worms Evolution
- A. Reconnaissance
- 重新认识——CSS Position定位
- A. What is for dinner?
- 设计模式:建造者模式(Builder)
- A. Reconnaissance 2
- A. Shell Game
- A. Extra-terrestrial Intelligence
- A. Towers