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平方英里,以初始水岸线为 ...
随机推荐
- tomcat在idea中启动乱码
server,localhost log,catalina log分别乱码 打开tomcat/conf/目录下修改logging.properties 找到"utf-8"行更改为 ...
- 使用JDBC进行简单的增删改查
JDBC为java的基础.用jdbc实现对数据库的增删改查的功能是程序员的基本要求.本例以mysql为例,首先要使用本例需要添加mysql-connector-java-5.1.7-bin.jar包. ...
- hybrid app开发中:苹果移动设备实用Meta标签
hybrid app开发中:苹果移动设备实用Meta标签 “apple-mobile-web-app-status-bar-style”作用是控制状态栏显示样式 具体效果如下: status-bar- ...
- 洛谷P1036 选数
题目描述 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n).从 n 个整数中任选 k 个整数相加,可分别得到一系列的和.例如当 n=4,k=3,4 个整数分别为 3,7,12, ...
- UVALive 4080 Warfare And Logistics (最短路树)
很多的边会被删掉,需要排除一些干扰进行优化. 和UVA - 1279 Asteroid Rangers类似,本题最关键的地方在于,对于一个单源的最短路径来说,如果最短路树上的边没有改变的话,那么最短路 ...
- java 读取文件转换成字符串
public String readFromFile(File src) { try { BufferedReader bufferedReader = new BufferedReader(new ...
- Node.js连接mysql报加密方式错误解决方案
本人在学习全栈开发过程中做一个Node的web项目在连接本地MySQL8.0版本的数据库时,发现Navicat连接不上,它报了一个数据库的加密方式导致连接不上的错误,错误如下: MySQL8.0版本的 ...
- kubernetes概念
kubernetes blog cluster cluster是计算.存储.和网络资源的集合,kubernetes利用这些资源运行各种基于容器的应用. master master是cluster的大脑 ...
- luogu愚人节比赛划水记
先放链接:愚人节比赛 说好的 不毒瘤 呢?题目都太神奇了吧! 管理员的脑洞orz T1 这个可以说是蒙数据蒙出来的,直接输出"0",AC T2 本机房dalao成功发现" ...
- 字符串数组 输入3个字符串,要求按由小到大的字母顺序输出; 输入n个学生的姓名和学号到字符串数组中,在输入一个姓名,如果班级有该生则返回其信息,否则返回本班无此人
输入3个字符串,要求按由小到大的字母顺序输出 如 输入franch england china,输出结果是china england franch 三个数排序输出,比较三个数的大小怎么做? a=18 ...