HDU 1303 Doubles
来源:互联网 发布:java 深度遍历 编辑:程序博客网 时间:2024/06/06 19:41
http://acm.hdu.edu.cn/showproblem.php?pid=1303
Doubles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K(Java/Others)
Total Submission(s): 1964 Accepted Submission(s):1361
Problem Description
As part of an arithmetic competencyprogram, your students will be given randomly generated lists offrom 2 to 15 unique positive integers and asked to determine howmany 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 programshould be able to scan the lists and output the correct answer foreach 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 18is twice 9.
1 4 3 2 9 7 18 22
your program should answer 3, as 2 is twice 1, 4 is twice 2, and 18is twice 9.
Input
The input file will consist of one ormore lists of numbers. There will be one list of numbers per line.Each list will contain from 2 to 15 unique positive integers. Nointeger will be larger than 99. Each line will be terminated withthe integer 0, which is not considered part of the list. A linewith the single number -1 will mark the end of the file. Theexample input below shows 3 separate lists. Some lists may notcontain any doubles.
Output
The output will consist of one line perinput list, containing a count of the items that are double someother item.
Sample Input
1 4 3 2 9 718 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
Recommend
Eddy
题目大意:一组数,以0结尾。寻找这组数当中有几对2倍数。也就是说,有几对数是2倍的关系。
分析:我又想起了哈希算法,总是能把问题很简单的处理掉。
代码如下:
#include<iostream>
using namespace std;
int main()
{
int n,i,count;
int x[200];
while(cin>>n)
{
if(n==-1) break;
memset(x,0,sizeof(x));
x[n]++;
x[2*n]++;
while(n)
{
cin>>n;
x[n]++;
x[2*n]++;
}
count=0;
for(i=1;i<200;i++)
if(x[i]>=2)
count++;
cout<<count<<endl;
}
return 0;
}
using namespace std;
int main()
{
}
阅读全文
0 0
- HDU 1303 Doubles
- hdu 1303 doubles …
- POJ 1552 Doubles (水题)
- hdu 1303 Doubles(模拟)
- HDU 1303 Doubles
- hdu 1303 Doubles
- hdu 1303 Doubles
- hdu 1303 Doubles
- HDU 1303 Doubles(水题)
- HDU 1303 Doubles
- hdu 1303 Doubles
- HDU 1242 Rescue
- ZZULI_SummerPractice(3) HDU 1…
- HDU 1579 Function Run Fun
- HDU 1405 The Last Practice
- HDU 2050 折线分割平面
- hdu 1000 A + B Problem
- HDU 1075 What Are You Talking …
- Cocos2dx3.10 VS2013添加 Json_Cpp第三方Json解析类库详细步骤
- 关于js函数中的 return
- centos 下配置ftp服务后 xftp工具无法上传与下载
- HDU 1323 Perfection
- 文件上传插件web uploader
- HDU 1303 Doubles
- HDU 1283 最简单的计算机
- 96PIN直插DIP千兆四口网络变压器 千兆交换机路由器网络滤波器
- HDU 1237 简单计算器
- Python列表、元组、集合、字典的区别和相互转换
- Retrofit2.0使用总结
- HDU 1282 回文数猜想
- HDU 1279 验证角谷猜想
- Android Studio用release模式进行调试