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


Source: Mid-Central USA 2003

题解

#include <iostream>
#include <vector>
using namespace std ;
int main(){
    int t ;
    while ( cin >> t && t != -1 ){
        vector<int> arr ;
        arr.push_back(t) ;
        int x ;
        while ( cin >> x && x ){
            arr.push_back(x) ;
        }
        int ans = 0 ;
        bool check[arr.size()] ;
        for ( int i = 0 ; i < arr.size() ; i ++ ){
            check[i] = false ;
        }
        for ( int i = 0 ; i < arr.size() ; i ++ ){
            for ( int j = 0 ; j < arr.size() ; j ++ ){
                if ( arr[i] * 2 == arr[j] ){
                    ans ++ ;
                    check[i] = true ;
//                    break ;
                }
                if ( arr[j] * 2 == arr[i] && arr[i] == true ){
                    ans ++ ;
                }
            }
        }
        cout << ans << endl ;
    }
    return 0 ;
}

原文地址:https://www.cnblogs.com/Cantredo/p/9949859.html

时间: 2024-11-14 10:58:52

ZOJ 1760 Doubles的相关文章

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 i

zoj 1760

#include<iostream>#include<set>using namespace std;int main(void){ while(true) { set<int> s; int n, doubles = 0; while(cin>>n && n) { if(n == -1) return 0; s.insert(n); if(s.find(2*n) != s.end()) doubles++; if(n%2 == 0 &

ZOJ 1760 &amp;&amp;POJ1552 Doubles (模拟)

链接:click here 题意:叫你求一个数是另一个数的二倍的这样的组合有多少个. 思路:纯模拟,一重循环:读入当前数据组a,并累积数据元素个数n,循环的结束标志是读入数据0,两重循环结构枚举组内所有数据对a[i] a[j] 判断是否成两倍关系 代码: #include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <algorithm>

zoj 1760 查找

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=760 撸了个二分查找 1 #include<iostream> 2 #include<cmath> 3 #include<iomanip> 4 #include<algorithm> 5 using namespace std; 6 7 int bs(int a[],int n,int len) 8 { 9 int lo = 0,hi =

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ - 2243 - Binary Search Heap Construction

先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal n