poj1552

Doubles

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 19154   Accepted: 11064

Description

As part of an arithmetic competency program, your students will be given randomly generated lists of from 2 to 15 unique positive integers and asked to determine how many items in each list are twice some other item in the same list. You will need a program to help you with the grading. This program should be able to scan the lists and output 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 is twice 1, 4 is twice 2, and 18 is twice 9.

Input

The
input will consist of one or more lists of numbers. There will be one
list of numbers per line. Each list will contain from 2 to 15 unique
positive integers. No integer will be larger than 99. Each line will be
terminated with the integer 0, which is not considered part of the list.
A line with the single number -1 will mark the end of the file. The
example input below shows 3 separate lists. Some lists may not contain
any doubles.

Output

The output will consist of one line per input list, containing a count of the items that are double some other item.

Sample Input

1 4 3 2 9 7 18 22 0
2 4 8 10 0
7 5 11 13 1 3 0
-1

Sample Output

3
2
0

Source

Mid-Central USA 2003

 1 #include <iostream>
 2 #include<cstring>
 3 using namespace std;
 4
 5 int main()
 6 {
 7     int a[20];
 8     cin>>a[0];
 9     while(a[0]!=-1)
10     {
11         int n =1;
12         int ans = 0;
13         for(;;n++)
14         {
15             cin>>a[n];
16             if(a[n]==0)
17                 break;
18         }
19         for(int i=0;i<n-1;i++)
20         {
21             for(int j=i+1;j<n;j++)
22                 if(a[i]*2==a[j]||a[i]==a[j]*2)
23                 ans++;
24         }
25         cout<<ans<<endl;
26         memset(a,0,sizeof(a));
27         cin>>a[0];
28     }
29     return 0;
30 }

poj1552

时间: 2024-07-31 16:52:31

poj1552的相关文章

ZOJ 1760 &amp;&amp;POJ1552 Doubles (模拟)

链接:click here 题意:叫你求一个数是另一个数的二倍的这样的组合有多少个. 思路:纯模拟,一重循环:读入当前数据组a,并累积数据元素个数n,循环的结束标志是读入数据0,两重循环结构枚举组内所有数据对a[i] a[j] 判断是否成两倍关系 代码: #include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <algorithm>

初探treap

treap的基本操作 treap类似二分查找树,只是加了一个堆,用随机值维护平衡,只是期望平衡.小数据下表现并不是特别优秀,但是足够用了. 先水两发,之后再继续搞- -. poj1338 Ugly Numbers 把质因子只含2,3,5的数叫Ugly Number.通式为: x=2i×3j×5k 注意到是一个幂次计算,因此大致地有: 0≤i,j,k≤30 那么我们只需要枚举∏(0≤i≤30,x=2,3,5)xi,然后排序即可.当然也可以直接logn地插入,于是可以用STL的set维护,这里不用s

Bailian2807 两倍【序列】

2807:两倍 描述 给定2到15个不同的正整数,你的任务是计算这些数里面有多少个数对满足:数对中一个数是另一个数的两倍. 比如给定1 4 3 2 9 7 18 22,得到的答案是3,因为2是1的两倍,4是2个两倍,18是9的两倍. 输入 一行,给出2到15个两两不同且小于100的正整数.最后用0表示输入结束. 输出 一个整数,即有多少个数对满足其中一个数是另一个数的两倍. 样例输入 1 4 3 2 9 7 18 22 0 样例输出 3 来源 翻译自Mid-Central USA 2003的试题