牛客练习赛33 B tokitsukaze and RPG (类埃筛)

链接:https://ac.nowcoder.com/acm/contest/308/B
来源:牛客网

tokitsukaze and RPG
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
tokitsukaze最近沉迷一款RPG。
这个RPG一天有k分钟,每一天从第1分钟开始。
有n种怪物,第i种怪物每天第一次出现的时间为Xi分钟,第二次出现的时间为2Xi分钟,第三次出现的时间为3Xi分钟......同一时刻出现的怪物种类越多,打怪获得的经验也越高。
为了高效练级,tokitsukaze想知道在一天内出现怪物种类最多的时间点会出现多少种怪物,这样的时间点有多少个。
输入描述:
第一行包括2个正整数n,k(1≤n≤10^5,1≤k≤10^6),表示有n种怪物,一天有k分钟。
接下来一行包括n个正整数X(1≤Xi≤10^6),含义如题面所示。
输出描述:
输出一行,包括两个整数a,b。
a表示怪物种类数,b表示时间点的个数。
示例1
输入
复制
3 6
2 2 3
输出
复制
3 1
说明
在第6分钟时,3种怪物都出现了。
示例2
输入
复制
3 5
2 2 3
输出
复制
2 2
说明
在第2分钟和第4分钟时,第一种和第二种怪物出现了。
示例3
输入
复制
6 10
1 2 3 4 5 6
输出
复制
4 1
说明
在第6分钟时,出现了第一种、第二种、第三种、第六种怪物。
示例4
输入
复制
3 5
6 6 6
输出
复制
0 5
说明
在第1分钟、第2分钟、第3分钟、第4分钟、第5分钟,都没有出现怪物。

题意:

思路:

记录 每一个x的个数,然后去重x数组,用类埃筛的方式去维护 数组 num[i] ,num[i] 代表 在i这个时间点有多少个怪兽出现。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <bits/stdc++.h>
//#include <bits/unordered_map.h>

#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int* p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

unordered_map<int, int> m;
int n, k;

ll num[maxn];
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\code_stream\\out.txt","w",stdout);
    gbtb;
    cin >> n >> k;
    int x;
    vector<int> v;
    repd(i, 1, n)
    {
        cin >> x;
        m[x]++;
        v.push_back(x);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)), v.end()); // 去重
    for (auto x : v)
    {
        for (int i = x; i <= k; i += x)
        {
            num[i] += m[x];
        }
    }
    ll ans1 = -1ll;
    ll ans2;
    repd(i, 1, k)
    {
        if (num[i] > ans1)
        {
            ans1 = num[i];
            ans2 = 1;
        } else if (num[i] == ans1)
        {
            ans2++;
        }
    }
    cout << ans1 << " " << ans2 << endl;



    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



转载于:https://www.cnblogs.com/qieqiemin/p/11182545.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值