zoj 1760 Doubles(set集合容器的应用)
题目链接:
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集合容器的应用)的更多相关文章
- zoj 1760 Doubles
Doubles Time Limit: 2 Seconds Memory Limit: 65536 KB As part of an arithmetic competency progra ...
- 【STL】 set集合容器常用用法
set集合容器:实现了红黑树的平衡二叉检索树的数据结构,插入元素时,它会自动调整二叉树的排列,把元素放到适当的位置,以保证每个子树根节点键值大于左子树所有节点的键值,小于右子树所有节点的键值:另外,还 ...
- Java集合容器简介
Java集合容器主要有以下几类: 1,内置容器:数组 2,list容器:Vetor,Stack,ArrayList,LinkedList, CopyOnWriteArrayList(1.5),Attr ...
- C++ STL set集合容器
汇总了一些set的常用语句,部分参考了这篇:http://blog.163.com/jackie_howe/blog/static/199491347201231691525484/ #include ...
- STL中的set集合容器进行集合运算:并、交、差实例
集合容器的集合运算:并.交.差: #include "stdafx.h" #include <iostream> #include <set> #inclu ...
- set集合容器
set集合容器几条特点 1.它不会重复插入相同键值的元素,而采取忽略处理 2.使用中序遍历算法,检索效率高于vector.deque.list容器,在插入元素时,会自动将元素按键值从小到大排列 3 ...
- python 标准类库-数据类型之集合-容器数据类型
标准类库-数据类型之集合-容器数据类型 by:授客 QQ:1033553122 Counter对象 例子 >>> from collections import Counter ...
- JAVA中的集合容器操作类
目录 JAVA中的集合容器操作类 List集合 ArrayList的操作方法说明 LinkedList Stack Set Map Queue 总结 JAVA中的集合容器操作类 Java容器类库总共分 ...
- multiset多重集合容器(常用的使用方法总结)
关于C++STL中multiset集合容器的学习,看别人的代码一百遍,不如自己动手写一遍. multiset多重集合容器和set集合容器的使用方法大多相同,不同的是multiset多重集合容器允许重复 ...
随机推荐
- bootstrap4.1下拉菜单
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...
- brctl命令
有五台主机.其中一台主机装有linux ,安装了网桥模块,而且有四块物理网卡,分别连接同一网段的其他主机.我们希望其成为一个网桥,为其他四台主机(IP分别为192.168.1.2 ,192.168.1 ...
- Sql递归关联情况,With作为开头条件。
with Test_Recursion(Id,ParentId)AS(select Id,ParentId from [V_KPI_DetailsActivities] where ParentId ...
- ctags的如何生成tags文件
tags 在使用vim编程和浏览代码是非常有用.可以用CTRL+]和CTRL+t 来回跳转关键字.先生成自己工作目录的tags.最简单粗暴用法: $cd yourwork $ctags -R * 这样 ...
- 定时任务 Wpf.Quartz.Demo.2
定时任务 Wpf.Quartz.Demo.1已经能运行了,本节开始用wpf搭界面. 准备工作: 1.界面选择MahApp.Metro 在App.xaml添加资源 <Application.Res ...
- ovs-appctl 命令合集
通用命令 exit 优雅关闭ovs-vswitchd进程 qos/show interface 查询内核中关于qos的配置以及和给出端口有关的状态 cfm/show [interface]显示在指定端 ...
- js中两种for循环的使用
针对两种for循环的使用 1. for in循环的使用环境 可用在字符串.数组.对象中, 需注意:其中遍历对象得到的是每个key 的value值 2. for 变量递加的方式 ...
- Django(ORM常用字段)
day68 参考:http://www.cnblogs.com/liwenzhou/p/8688919.html 1. Django ORM常用字段: 1. AutoField ...
- javaweb项目中的过滤器的使用
翻阅博客园的的时候,看到两篇关于javaweb过滤器的帖子写的很好,这里备忘一下: 过滤器基础:http://www.cnblogs.com/xdp-gacl/p/3948353.html 获取器案例 ...
- ss的使用配置(电脑、手机FQ)
注:FQ仅用于google查阅资料等,禁止违规违法行为 自己搭建ss服务 1.vps购买:https://www.alpharacks.com/holiday 按流程填完相关信息(Operating ...