题目链接:

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++ 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 标准类库-数据类型之集合-容器数据类型

    标准类库-数据类型之集合-容器数据类型   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. ASP.NET MVC Form表单验证与Authorize特性

    一.Form表单验证 1.基本概念 表单验证是一个基于票据(ticket-based)[也称为基于令牌(token-based)]的系统.当用户登录系统以后,会得到一个包含基于用户信息的票据(tick ...

  2. Python自动化开发 - 字符编码、文件和集合

    本节内容 字符编码 文件操作 集合 一.字符编码 1.编码 计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.解决思路:数字与符号建立一对一映射,用不同数字表示不同符号. ASCI ...

  3. datatable fix error–Invalid JSON response

    This error is pretty common. Meaning:When loading data by Ajax(ajax|option).DataTables by default, e ...

  4. 【VB6】全局键盘钩子

    基本也没啥好说的,不要用到木马及恶意程序中是以前从VB.NET程序改到VB6的,阉割了一些功能,只提供键盘Hook功能想要截获热键可以在处理函数中返回1,里面有示例 下载地址 http://pan.b ...

  5. .NET MVC 学习笔记(四)— 基于Bootstarp自定义弹出框

    .NET MVC 学习笔记(四)—— 基于Bootstarp自定义弹出框 转载自:https://www.cnblogs.com/nele/p/5327380.html (function ($) { ...

  6. 使用ActionFilterAttribute实现MVC后台授权

    授权就是我们在用户未登录的情况下不允许访问一些页面,只有登录后才能进行访问一些页面. 在mvc中我们可以使用ActionFilterAttribute来进行授权验证来阻止一些未经授权的直接访问的页面. ...

  7. springBoot2 基础语法

    请求响应 request对象 request 对象其实是HttpServletRequest 类型, 通过它可以获取请求相关的一切信息, 包含请求信息 . 以及请求参数 ,甚至可以当成往里面存储数据[ ...

  8. docker容器备份、恢复和迁移volume方案

    volume作为数据的载体,在很多情况下需要对其中的数据进行备份.迁移或是恢复.下面一docker容器的volume为例,说一下备份的技巧. 我们先建立一个容器vol_simple,该容器在/date ...

  9. Akka(0):聊聊对Akka的初步了解和想法

    前一段时间一直沉浸在函数式编程模式里,主要目的之一是掌握一套安全可靠的并发程序编程方法(concurrent programming),最终通过开源项目FunDA实现了单机多核CPU上程序的并行运算. ...

  10. IOS渗透测试第一步-基础知识统一放送

    原文: http://www.websecgeeks.com/2017/04/ios-application-pentesting-part-3.html http://www.websecgeeks ...