zoj 1760 Doubles
Doubles
Time Limit: 2 Seconds Memory Limit: 65536 KB
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
分析:用set,检索速度快
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
int main(){
set<int> s;
int n, sum;
while(cin >> n){
if(n == -)
break;
sum = ;
s.clear();
s.insert(n);
while(cin >> n){
if(n == )
break;
s.insert(n);
}
set<int>::iterator it = s.begin();
while(it != s.end()){
if(s.find( * (*it)) != s.end())
sum++;
it++;
}
cout << sum << endl;
}
return ;
}
zoj 1760 Doubles的更多相关文章
- zoj 1760 Doubles(set集合容器的应用)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1760 题目描述: As part of an arithmet ...
- zoj 1760 floyd构图+Dinic最大流
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 #include <cstdio> #includ ...
- zoj 1760 查找
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=760 撸了个二分查找 #include<iostream> #inc ...
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
随机推荐
- 88E1111
千兆网phy芯片 支持GMII,RGMII,MII等接口 具备4个GMII时钟模式 支持自适应功能 超低功耗模式 功率降低模式 MDC/MDIO/TWSI接口 支持10Mb/s,100Mb/s,100 ...
- 查看Windows激活信息
使用 Windows + R组合快捷键打开运行命令框 1.运行: slmgr.vbs -dlv 可以查询到Win10的激活信息,包括:激活ID.安装ID.激活截止日期等信息. 2.运行: slmgr. ...
- @AutoWired注解使用时可能会发生的错误
@Autowired注解:用于对Bean的属性变量.属性的set方法及构造函数进行标注,配合对应的注解处理器完成Bean的自动配置工作.@Autowired注解默认按照Bean类型进行装配. 1.在 ...
- UVA 10817 - Headmaster's Headache(三进制状压dp)
题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&pag ...
- 数据倾斜是多么痛?spark作业调优秘籍
目录视图 摘要视图 订阅 [观点]物联网与大数据将助推工业应用的崛起,你认同么? CSDN日报20170703——<从高考到程序员——我一直在寻找答案> [直播]探究L ...
- docker安装Tensorflow并使用jupyter notebook
目前网上提供的大多数的方法都是如下: docker pull tensorflow/tensorflow docker run -it -p : tensorflow/tensorflow 但是按照步 ...
- MAC 安装汇编编译工具 NASM
直接运行nasm报错: 开始安装: brew reinstall nasm
- 四、绘图可视化之Seaborn
Seaborn-Powerful Matplotlib Extension seaborn实现直方图和密度图 import numpy as np import pandas as pd import ...
- Lazy Instantiator
lazy instantiator (懒加载.延迟实例化.延迟初始化) 最开始看斯坦福的视频,对 延迟初始化 这个概念,不太理解 只见到,有些属性的初始化是在init做的,有些是在viewDidLoa ...
- vue 封装组件上传img
var _uploadTemplate = '<div>'+ '<input type="file" name="file" v-on:cha ...