题目链接:

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. IDHTTP的基本用法

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  2. 分形之二叉树(Binary Tree)

    上一篇文章讲的是分形之树(Tree),这一篇中将其简化一下,来展示二叉分形树的生长过程. 核心代码: static void FractalBinaryTree(const Vector3& ...

  3. @requestParamore与@pathvariable的区别

    http://localhost:8080/Springmvc/user/page.do?pageSize=3&pageNow=2 你可以把这地址分开理解,其中问号前半部分:http://lo ...

  4. Gimp RGB 转 CMYK

    安装GIMP separate+插件.在Windows的Photoshop中,有转换CMYK的功能,非常简单.在Linux里,通常用GIMP进行转换.由于授权的问题,默认安装的GIMP里没有安装转换的 ...

  5. wpf 导出Excel

    private void Button_Click_1(object sender, RoutedEventArgs e) { ExportDataGridSaveAs(true, this.data ...

  6. XML随笔:语法快速入门及当下流行的RSS简析

    今天是本人第一次写博客,之前闭门造车闹出过很多笑话,恰巧这几天刚刚重温了一遍XML的知识,决定把XML的知识再来从头到尾的理一遍,感触颇多,今天分享给大家.希望大家能多多注意其中的要点. 1.定义 首 ...

  7. 【文文殿下】 [USACO08MAR]土地征用 题解

    题解 斜率优化裸题. 有个很玄学的事情,就是我用\(f[i]=min\{f[j-1]+p[j].y*p[i].x\}\) 会很奇怪的Wa . 明明和\(f[i]=min\{f[j]+p[j+1].y* ...

  8. 前端基础-html 字体标签,排版标签,超链接,图片标签

    主要内容: 字体标签: h1~h6.<font>.<u>.<b>.<strong><em>.<sup>.<sub> ...

  9. 网页关闭(解决window.close在火狐下不兼容问题)

    熟悉前端的都知道,火狐默认状态非window.open的页面window.close是无效的 网上有很多人说,在火狐的地址栏输入:about:config然后找到dom.allow_scripts_t ...

  10. 二分查找的实现(java版本)

    一.二分法查找的定义 依次将所查找数据与中心数据对比,根据大小调整数据边界二.二分查找的条件 数组必须排序三.二分查找的原理 四.二分法查找的代码 /* * 从数组当中找到4所在的索引: * {2,4 ...