zoukankan      html  css  js  c++  java
  • hdu 1303 Doubles

    题目连接

    http://acm.hdu.edu.cn/showproblem.php?pid=1303

    Doubles

    Description

    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.

    SampleInput

    1 4 3 2 9 7 18 22 0
    2 4 8 10 0
    7 5 11 13 1 3 0
    -1

    SampleOutput

    3
    2
    0

    刷些水题打发时间。。

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<vector>
     7 #include<map>
     8 #include<set>
     9 using std::cin;
    10 using std::cout;
    11 using std::endl;
    12 using std::find;
    13 using std::sort;
    14 using std::set;
    15 using std::map;
    16 using std::pair;
    17 using std::vector;
    18 using std::multiset;
    19 using std::multimap;
    20 #define sz(c) (int)(c).size()
    21 #define all(c) (c).begin(), (c).end()
    22 #define iter(c) decltype((c).begin())
    23 #define cls(arr,val) memset(arr,val,sizeof(arr))
    24 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
    25 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
    26 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
    27 #define pb(e) push_back(e)
    28 #define mp(a, b) make_pair(a, b)
    29 const int Max_N = 100010;
    30 typedef unsigned long long ull;
    31 set<int> res;
    32 int main() {
    33 #ifdef LOCAL
    34     freopen("in.txt", "r", stdin);
    35     freopen("out.txt", "w+", stdout);
    36 #endif
    37     int v;
    38     while (~scanf("%d", &v) && ~v) {
    39         int sum = 0;
    40         res.insert(v);
    41         while (~scanf("%d", &v) && v) res.insert(v);
    42         tr(res, ite) {
    43             if (res.find(*ite << 1) != res.end()) sum++;
    44         }
    45         printf("%d
    ", sum);
    46         res.clear();
    47     }
    48     return 0;
    49 }
    View Code
    By: GadyPu 博客地址:http://www.cnblogs.com/GadyPu/ 转载请说明
  • 相关阅读:
    JS中实现跨域的方法总结
    stack overflow错误分析
    VC包含目录、附加依赖项、库目录及具体设置
    sqlite3使用简介
    虚拟机开机提示Operating System not found解决办法
    Qt环境搭建(Qt Creator)+Visual Studio
    QT自定义信号
    不同平台文件读写的操作
    CNN大战验证码
    RNN入门(一)识别MNIST数据集
  • 原文地址:https://www.cnblogs.com/GadyPu/p/4575636.html
Copyright © 2011-2022 走看看