• D. Multiple Testcases (简单数学)


    题目链接:https://codeforces.com/contest/1342/problem/D

    想法:

    我们首先预处理出 >= i 的个数

    然后我们每次取遍历每个 i 然后可以得到最小的分组的个数

    利用最小的组数我们可以从 1 开始跳着选取就好了

    具体的还是看代码

    #pragma GCC optimize(2)
    #pragma GCC optimize(3)
    
    #include <algorithm>
    #include <string>
    #include <cstring>
    #include <vector>
    #include <map>
    #include <stack>
    #include <set>
    #include <queue>
    #include <cmath>
    #include <cstdio>
    #include <iomanip>
    #include <ctime>
    #include <bitset>
    #include <cmath>
    #include <sstream>
    #include <iostream>
    
    #define ll long long
    #define ls nod<<1
    #define rs (nod<<1)+1
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define INF 0x3f3f3f3f3f3f3f3f
    #define max(a, b) (a>b?a:b)
    #define min(a, b) (a<b?a:b)
    
    
    const double eps = 1e-10;
    const int maxn = 2e5 + 10;
    const int MOD = 998244353;
    
    int sgn(double a) { return a < -eps ? -1 : a < eps ? 0 : 1; }
    
    using namespace std;
    
    int a[maxn], b[maxn], sum[maxn];
    
    int main() {
        ios::sync_with_stdio(false);
        int n, k;
        cin >> n >> k;
        memset(sum, 0, sizeof(sum));
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            sum[a[i]]++;
        }
        for (int i = 1; i <= k; i++) {
            cin >> b[i];
        }
        for (int i = k - 1; i >= 0; i--)
            sum[i] = sum[i + 1] + sum[i];
        sort(a + 1, a + 1 + n);
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            ans = max(ans, sum[a[i]] / b[a[i]] + bool(sum[a[i]] % b[a[i]]));
        }
        cout << ans << endl;
        for (int i = 1; i <= ans; i++) {
            int cnt = 0, now = i;
            while (now <= n) {
                cnt++;
                now += ans;
            }
            cout << cnt << " ";
            now = i;
            while (now <= n) {
                cout << a[now] << " ";
                now += ans;
            }
            cout << endl;
        }
        return 0;
    }
  • 相关阅读:
    android: LayoutInflater使用
    android:ListView bbs Demo
    android:制作 Nine-Patch 图片
    android:单位和尺寸
    android:提升 ListView 的运行效率
    android:定制 ListView 的界面
    android:ListView 的简单用法
    android:创建自定义控件
    android:四种基本布局
    android:ProgressDialog控件
  • 原文地址:https://www.cnblogs.com/-Ackerman/p/13200411.html
Copyright © 2020-2023  润新知