Topic Connection
http://acm.hdu.edu.cn/showproblem.php?pid=1303
Doublesdescription
As part of a arithmetic competency program, your students would be given randomly generated lists of from 2 to the unique P ositive integers and asked to determine what many items in each list is twice some other item in the same list. You'll need a program to help you with the grading. This program should is able to scan the lists and output of the correct answer for each one. For example, given the list
1 4 3 2 9 7 18 22
Your program should answer 3, as 2 are twice 1, 4 is twice 2, and are twice 9.
Input
The input file is consist of one or more lists of numbers. There would be a list of numbers per line. Each list would contain from 2 to the unique positive integers. No integer would be larger than 99. Each line would be terminated with the integer 0, which was not considered part of the list. A line with the number-1 would mark the end of the file. The example input below shows 3 separate lists. Some lists may not be contain any doubles.
Output
The output would consist of one line per input list, containing a count of the items is double some other item.
Sampleinput
1 4 3 2 9 7 18 22 0
2 4 8) 10 0
7 5 11 13 1 3 0
-1
Sampleoutput
3
2
0
Brush some water questions to pass the time.
1#include <algorithm>2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <vector>7#include <map>8#include <Set>9 usingstd::cin;Ten usingstd::cout; One usingStd::endl; A usingStd::find; - usingStd::sort; - usingSTD::Set; the usingStd::map; - usingstd::p air; - usingstd::vector; - usingStd::multiset; + usingStd::multimap; - #defineSZ (c) (int) (c). Size () + #defineAll (c) (c). Begin (), (c). End () A #defineITER (c) Decltype ((c). Begin ()) at #defineCLS (arr,val) memset (arr,val,sizeof (arr)) - #defineCpresent (c, E) (Find (All (c), (e))! = (c). End ()) - #defineRep (i, n) for (int i = 0; i < (int) (n); i++) - #defineTR (c, I) for (ITER (c) i = (c). Begin (); I! = (c). end (); ++i) - #definePB (E) push_back (e) - #defineMP (A, b) Make_pair (A, B) in Const intMax_n =100010; -typedef unsignedLong Longull; to Set<int>Res; + intMain () { - #ifdef LOCAL theFreopen ("In.txt","R", stdin); *Freopen ("OUT.txt","w+", stdout); $ #endifPanax Notoginseng intv; - while(~SCANF ("%d", &v) && ~v) { the intsum =0; + Res.insert (v); A while(~SCANF ("%d", &v) &&v) res.insert (v); the TR (res, ite) { + if(Res.find (*ite <<1)! = Res.end ()) sum++; - } $printf"%d\n", sum); $ res.clear (); - } - return 0; the}
View Code
HDU 1303 Doubles