CF1342D Multiple Testcases(构造题)
题意
有 nnn 个数 {ai}\{a_i\}{ai},每个 ai≤ka_i\leq kai≤k 。
每个背包大于等于 iii 的数的个数不能超过 ci(i=1,2,..,k)c_i(i=1,2,..,k)ci(i=1,2,..,k)。
问最少要多少个背包才能放所有数,并且输出每个背包中的数。
n,k≤200000n,k \leq 200000n,k≤200000
分析
完了小号也上紫了(要被迫打div1了
比赛时写了沙雕线段树,比较复杂。
题解给了比较简单的做法。
先求出总共要多少个背包 cntcntcnt,再将每个数均匀分配到背包中。
那么 cntcntcnt 怎么求呢?
假设大于等于 ttt 的数有 btb_tbt 个,那么根据抽屉原理,背包个数要大于等于 ⌈btct⌉\lceil\frac{b_t}{c_t}\rceil⌈ctbt⌉。
所以背包个数就是 cnt=max{⌈btct⌉}cnt=\max\{\lceil\frac{b_t}{c_t}\rceil\}cnt=max{⌈ctbt⌉}。
接下来怎么构造方案呢?
将 aia_iai 从小到大排序,假设 aia_iai 有 tit_iti 个。接下来只用把第 iii 个放进第 imodcnti~mod~cnti mod cnt 个背包即可。因为这样一个背包中 aia_iai 的个数不会超过 ⌈ticnt⌉\lceil\frac{t_i}{cnt}\rceil⌈cntti⌉ 个。
复杂度为 O(nlogn)O(nlogn)O(nlogn),其实就是排序的复杂度=。=
代码如下
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define N 200005
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
struct custom_hash {static uint64_t splitmix64(uint64_t x) {x += 0x9e3779b97f4a7c15;x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;x = (x ^ (x >> 27)) * 0x94d049bb133111eb;return x ^ (x >> 31);}size_t operator()(uint64_t x) const {static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x + FIXED_RANDOM);}
};
LL z = 1;
int read(){int x, f = 1;char ch;while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;x = ch - '0';while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;return x * f;
}
int ksm(int a, int b, int p){int s = 1;while(b){if(b & 1) s = z * s * a % p;a = z * a * a % p;b >>= 1;}return s;
}
int a[N], c[N], tot, cnt;
vector<int> ans[N];
int main(){int i, j, n, k, m;n = read(); k = read();for(i = 1; i <= n; i++) a[i] = read();sort(a + 1, a + i);for(i = 1; i <= k; i++) c[i] = read();for(i = n; i >= 1; i--) cnt = max(cnt, (n - i) / c[a[i]] + 1);for(i = 1; i <= n; i++) ans[i % cnt].push_back(a[i]);printf("%d\n", cnt);for(i = 0; i < cnt; i++){printf("%d ", ans[i].size());for(auto x: ans[i]) printf("%d ", x);printf("\n");}return 0;
}
CF1342D Multiple Testcases(构造题)相关推荐
- CDMA(牛客第八场构造题)
链接:https://ac.nowcoder.com/acm/contest/888/C 来源:牛客网 Gromah and LZR have entered the third level. The ...
- CodeForces 459C(构造题)
http://codeforces.com/problemset/problem/459/C /** 题意:有n个同学,k辆车,d天(每天n个同学去一个地方)问经过d天后,任意的多个同学不能总在一起d ...
- Codeforces 482 - Diverse Permutation 构造题
这是一道蛮基础的构造题. - k +(k - 1) -(k - 2) 1 + k , 1 , k , 2, ....... ...
- hdu 5710 Digit-Sum (构造题)
题目链接:hdu 5710 Digit-Sum 题意: 定义S(n)=n的数位和,给你一个a,b让你找一个n使得a*S(n)=b*S(2n). 题解: 传送门 构造题很少做啊!! 太弱了 1 #inc ...
- CF1110E Magic Stones(构造题)
这场CF怎么这么多构造题-- 题目链接:CF原网 洛谷 题目大意:给定两个长度为 $n$ 的序列 $c$ 和 $t$.每次我们可以对 $c_i(2\le i<n)$ 进行一次操作,也就是把 $c ...
- 字符串——BZOJ 3097: Hash Killer I【构造题,思维题】
BZOJ 3097: Hash Killer I[构造题,思维题] 题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3097 题意:让你出一组 ...
- CSUSTOJ-小樱的库洛牌(恶心的构造题)
题目连接:http://acm.csust.edu.cn/problem/4020 博客园食用链接:https://www.cnblogs.com/lonely-wind-/p/13941902.ht ...
- Codeforces Global Round 8 C. Even Picture 题解[巧妙法构造题]
C. Even Picture 题目大意:让你构造一个连通图,图中有k个灰点其中n个点4面都是灰点,(k-n)个点周围2个点是灰点 我们设最上面的为(1,1)点就可以了 ps:exactly:只有,其 ...
- AT4505-[AGC029F]Construction of a tree【构造题,hall定理,网络流】
正题 题目链接:https://www.luogu.com.cn/problem/AT4505 题目大意 给出nnn个点和n−1n-1n−1个点集UiU_iUi,每个点集中选择两个点连边使得该图是一 ...
最新文章
- android-oculus
- latex公式对齐_论文中的公式如何对齐
- hdu3695(AC自动机)
- Spring与Quartz的整合实现定时任务调度
- [CodeJam 2021 Round 3] Square Free(调整法 / 字典序最小解网络流)
- SQLite | SQLite 与 Pandas 比较篇之一
- linux 一次执行多条命令
- html div三角形,【div】纯CSS绘制三角形
- iPhone质量成迷?被吴彦祖一箭射穿,却还能开机
- mysql 拼音首字母_Mysql:拼音首字母查询(超高性能)
- plc tcp ip通讯怎么只能连一个客户端_如何远程读取西门子PLC数据?
- (转)倒卖火车票的惊人黑幕全过程
- Excel: 如何对Excel2007工作表做统一编辑修改
- JQui---------Button心得
- 云计算中网络基础知识
- (SEED-Lab) DNS_Local Attack Lab
- python与seo实战课程it技术_python与SEO实战课程学习B计划
- 【巴什博弈 抢夺资源】
- 【强烈推荐收藏】坚持3个月爆肝华为机试108题C++全解(适合新手入门,就业必刷套题)
- python turtle画圣诞树动图_用 turtle 画一棵圣诞树