zoukankan      html  css  js  c++  java
  • PAT 天梯赛 L1-020. 帅到没朋友 【STL】

    题目链接

    https://www.patest.cn/contests/gplt/L1-020

    思路
    对于每个 K >= 2 的朋友圈,里面的所有 ID 都用 MAP 标记一下
    对于每个 K == 1 的朋友圈,里面的 ID 只要输入就不用管

    然后在查找的时候 只要查找一下 这个 ID是否被 MAP 标记为 1
    然后每输出的那个 ID 用 MAP 标记 防止 多次查询

    但是要注意,如果用 INT 来存放 ID 输出的时候 要用%05d

    AC代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    
    using namespace std;
    typedef long long LL;
    
    const double PI = 3.14159265358979323846264338327;
    const double E = 2.718281828459;
    const double eps = 1e-6;
    
    const int MAXN = 0x3f3f3f3f;
    const int MINN = 0xc0c0c0c0;
    const int maxn = 1e2 + 5;
    const int MOD = 1e9 + 7;
    
    int main()
    {
        int n;
        cin >> n;
        map <int, int> M;
        M.clear();
        for (int i = 0; i < n; i++)
        {
            int m;
            cin >> m;
            if (m >= 2)
            {
                for (int j = 0; j < m; j++)
                {
                    int num;
                    cin >> num;
                    M[num] = 1; 
                }   
            }
            else
            {
                int num;
                cin >> num;
            }
        }
        int m;
        cin >> m;
        int i, j;
        for (i = 0, j = 0; i < m; i++)
        {
            int num;
            cin >> num;
            if (M[num] == 0)
            {
                if (j)
                    printf(" ");
                else
                    j++;
                printf("%05d", num);
                M[num] = 1;
            }
        }
        if (j == 0)
            printf("No one is handsome");
        cout << endl;
    }
  • 相关阅读:
    LIBSVM
    tf-idf
    DIV+CSS例子
    网页背景设置
    获取JDBC中的ResultSet的记录的条数
    SQL 基本语句
    经典SQL语句大全
    JS(截取字符串,显示当前系统时间yyyy-MM-dd,从文本框得到的数值计算)
    JavaScript实现全排列
    Java发送邮件
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433289.html
Copyright © 2011-2022 走看看