zoj 1760 Doubles(set集合容器的应用)

时间:2022-10-21 11:11:34

题目链接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1760

题目描述:

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 file 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

 /*问题 求一串数字中存在谁是谁的两倍的关系的个数
解题思路 问题很简单,主要是使用了STL中的set集合,查询起来速度是极快的。*/
#include <set>
#include <cstdio>
using namespace std; int main()
{
int n,sum;
set<int> s;
set<int>::iterator it;
while()
{
scanf("%d",&n);
if(n == -) break;
if(n == )
{
sum=;
for(it=s.begin(); it != s.end();it++){
if(s.find(*(*it)) != s.end())
sum++;
}
printf("%d\n",sum);
s.clear();
}
else
s.insert(n);
}
return ;
}

zoj 1760 Doubles(set集合容器的应用)的更多相关文章

  1. zoj 1760 Doubles

    Doubles Time Limit: 2 Seconds      Memory Limit: 65536 KB As part of an arithmetic competency progra ...

  2. 【STL】 set集合容器常用用法

    set集合容器:实现了红黑树的平衡二叉检索树的数据结构,插入元素时,它会自动调整二叉树的排列,把元素放到适当的位置,以保证每个子树根节点键值大于左子树所有节点的键值,小于右子树所有节点的键值:另外,还 ...

  3. Java集合容器简介

    Java集合容器主要有以下几类: 1,内置容器:数组 2,list容器:Vetor,Stack,ArrayList,LinkedList, CopyOnWriteArrayList(1.5),Attr ...

  4. C&plus;&plus; STL set集合容器

    汇总了一些set的常用语句,部分参考了这篇:http://blog.163.com/jackie_howe/blog/static/199491347201231691525484/ #include ...

  5. STL中的set集合容器进行集合运算:并、交、差实例

    集合容器的集合运算:并.交.差: #include "stdafx.h" #include <iostream> #include <set> #inclu ...

  6. set集合容器

      set集合容器几条特点 1.它不会重复插入相同键值的元素,而采取忽略处理 2.使用中序遍历算法,检索效率高于vector.deque.list容器,在插入元素时,会自动将元素按键值从小到大排列 3 ...

  7. python&&num;160&semi;标准类库-数据类型之集合-容器数据类型

    标准类库-数据类型之集合-容器数据类型   by:授客 QQ:1033553122 Counter对象 例子 >>> from collections import Counter ...

  8. JAVA中的集合容器操作类

    目录 JAVA中的集合容器操作类 List集合 ArrayList的操作方法说明 LinkedList Stack Set Map Queue 总结 JAVA中的集合容器操作类 Java容器类库总共分 ...

  9. multiset多重集合容器(常用的使用方法总结)

    关于C++STL中multiset集合容器的学习,看别人的代码一百遍,不如自己动手写一遍. multiset多重集合容器和set集合容器的使用方法大多相同,不同的是multiset多重集合容器允许重复 ...

随机推荐

  1. Smack4&period;1注册新用户

    更新了smack4.1后,发现之前的注册表单不能使用了,很多属性都不能使用. 发现4.1把帐号的出来都集中到 org.jivesoftware.smackx.iqregister.AccountMan ...

  2. c&num; 反射应用之工厂

    反射是.net的核心功能,十分的强大.但是好像微软封装的太过了,作为程序员,在实际项目中我很少用到反射(估计是参加的大型项目太少了,需要交互第三方的项目太少了). 工厂模式是软件设计模式中重要的一种, ...

  3. CentOS下安装setuptools、pip和virtualenv

    已经安装了Python,现在我们可以最终确定完成应用程序生产和部署的基础知识.为此,我们将设立两个最常用的工具:PIP封装经理和virtualenv中的环境管理. 一.安装setuptools set ...

  4. Oracle用户,权限,角色以及登录管理 scoot 授权

    Oracle用户,权限,角色以及登录管理 1. sys和system用户的区别 system用户只能用normal身份登陆em.除非你对它授予了sysdba的系统权限或者syspoer系统权限. sy ...

  5. android 系统应用在运行时被卸载

    android 系统应用在运行时被rm 掉了,是否还会运行? 环境:root,且开机运行 经过试验,apk本身是在 /system/app 目录下面,且apk已经运行了,这个时候直接 rm /syst ...

  6. TweenMax动画库学习&lpar;六&rpar;

    目录            TweenMax动画库学习(一)            TweenMax动画库学习(二)            TweenMax动画库学习(三)            Tw ...

  7. 【前端学习】【jQuery选择器】

    jQuery选择器     jQuery选择器 本文内容引自于单东林<锋利的jQuery>,未经原作者准许,禁止以商业目的转载发布! 选择器是jQuery的根基,在jQuery中,对事件处 ...

  8. javascript 写一段代码,判断一个字符串中出现次数最多的字符串,并统计出现的次数

    javascript 写一段代码,判断一个字符串中出现次数最多的字符串,并统计出现的次数 function test(){ var bt = document.getElementById(&quot ...

  9. Unity UGUI图文混排&lpar;七&rpar; -- 下划线

    之前更新超链接的时候,忘了搭配实现一个下划线的功能,这篇文章就是来补上这一个功能,时间有点长,一方面没有很好的思路,一方面也没多少时间. 先在网上收集了一下下划线的实现操作,一种是在文本下再创建一个文 ...

  10. linux下sophos,clamav&plus;clamtk杀毒软件

    以deepin为例 avast for linux sophos for linux comodo for linux 目前能够在官网找到. 先说clamav clamav 听说很活跃,clamav是 ...