<cf>Worms Evolution
来源:互联网 发布:php函数参考大全 pdf 编辑:程序博客网 时间:2024/05/21 07:15
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms 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 nspace-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.
51 2 3 5 7
3 2 1
51 8 1 5 1
-1
想了很久,后来才发觉直接暴力解决就可以轻松过,完全不用任何优化。直接cin然后三重for loop暴力遍历所有组合。我优化了一下,然后发觉跟直接暴力用时完全一样T.T
AC Code:
#include <cstdio>#include <algorithm>#include <iostream>using namespace std;struct Num{ int idx;//index int val;//value}a[1001];int cmp(const void *xx,const void *yy){ struct Num *x=(Num*)xx; struct Num *y=(Num*)yy; return x->val-y->val;}int main(){ int n; int i,j,k; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i].val); a[i].idx=i; } qsort(&a[1],n,sizeof(a[1]),cmp); for(i=1;i<n;i++) for(j=i+1;j<n;j++) for(k=j+1;k<=n;k++) { if(a[k].val==a[i].val+a[j].val) { printf("%d %d %d\n",a[k].idx,a[i].idx,a[j].idx); goto loop;//这样退出较快 } else if(a[k].val>a[i].val+a[j].val) break; } puts("-1"); loop: return 0;}
- <cf>Worms Evolution
- A. Worms Evolution
- CF 474B Worms
- 【水搜索】#31 A. Worms Evolution
- Worms
- CF 271 A Keyboard B Worms C Captain Marmot
- [CF 712C] Memory and De-Evolution
- evolution
- evolution
- evolution
- evolution
- CF#712 C. Memory and De-Evolution (数学)
- CF 712C. Memory and De-Evolution 贪心
- CF#712 C. Memory and De-Evolution(水题)
- HDU4404 Worms
- B. Worms
- B. Worms
- Google Search API Worms
- 工程师唱主角 2012 SDCC中国软件开发者大会启动
- VC控件资料汇总--------列表控件 .
- unable to resolve ... for transcoding
- Google MapReduce中文版
- FilenameFilter的几种基本用法
- <cf>Worms Evolution
- Android软件开发之盘点所有Dialog对话框大合集(一)
- WARN No appenders could be found for logger的解决方法
- Cygwin编译Mplayer笔记
- win7卸载ie9降级到ie8或ie7
- twitter storm 配置项6.0
- VC 列表控件 CListCtrl成员
- git rebase
- 标准正态分布函数表的程序实现