【cf contest 1119 G】Get Ready for the Battle
题目
你有\(n\)个士兵,需要将他们分成\(m\)组,每组可以为0;
现在这些士兵要去攻打\(m\)个敌人,每个敌人的生命值为\(hp_i\) ;
一轮游戏中一组士兵选定一个攻打的敌人,敌人生命值-=这组的人数;
胜利的判定是所有敌人的生命值为非正的;
输出胜利的最小轮数,可以达到最小轮数的分配方式,并输出每轮的策略;
\(1 \le m \le n \le 10^6 \ , \ 1 \le \sum hp_i \le 10^6\) ;
题解
答案的下界是\(\lceil \frac{\sum_{i=1}^{m} \ hp_i} n \rceil\) ,考虑构造这个下界;
注意到所有的和为\(n\),首先让 $ hp_i $ 对 $ n $ 取模;
只需要构造
\[\begin{cases}
s_i &= (\sum_{j=1}^{i} hp_j) \ mod \ n &i \lt m \\
s_i &= n &i = m \\
\end{cases}
\]排序得到\(s_1,\cdots,s_{m-1},s_m\),构造\(s_i-s_{i-1}\)即可;
容易知道只有最后一次的\(n\)没有被充分利用,所以满足下界;
再 \(for\) 一遍模拟取模的过程求出策略即可;
#include<bits/stdc++.h>
#define mk make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
const int N=1000010;
int n,m,a[N],pos[N],cnt;
pair<int,int>b[N];
vector<int>ans[N];
char gc(){
static char*p1,*p2,s[1000000];
if(p1==p2)p2=(p1=s)+fread(s,1,1000000,stdin);
return(p1==p2)?EOF:*p1++;
}
int rd(){
int x=0;char c=gc();
while(c<'0'||c>'9')c=gc();
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+c-'0',c=gc();
return x;
}
char ps[1000000],*pp=ps;
void flush(){
fwrite(ps,1,pp-ps,stdout);
pp=ps;
}
void push(char x){
if(pp==ps+1000000)flush();
*pp++=x;
}
void write(int x){
static int sta[20],top;
if(!x){push('0');return;}
while(x)sta[++top]=x%10,x/=10;
while(top)push(sta[top--]^'0');
}
int main(){
// freopen("G.in","r",stdin);
// freopen("G.out","w",stdout);
n=rd();m=rd();
for(int i=1;i<=m;++i){
a[i]=rd();
int tmp=a[i]/n;
for(int k=1;k<=tmp;++k)
for(int j=1;j<=m;++j)ans[j].pb(i);
a[i]%=n;
}
for(int i=1,now=0;i<=m;++i){
now+=a[i];
if(now>=n)now-=n;
if(i!=m)b[i]=mk(now,i);
}
sort(b+1,b+m);
b[m]=mk(n,m);
b[0]=mk(0,0);
for(int i=1;i<=m;++i)pos[b[i].se]=i;
for(int i=1,lst=1,now=0;i<=m;++i){
now+=a[i];
if(now>=n){
for(;lst<=m;++lst)ans[lst].pb(i);
lst=0;now-=n;
}
if(!now)continue;
for(;lst<=pos[i];++lst)ans[lst].pb(i);
}
cnt=ans[1].size();
write(cnt),push('\n');
for(int i=1;i<=m;++i)write(b[i].fi-b[i-1].fi),push(' ');
push('\n');
for(int i=0;i<cnt;++i){
for(int j=1;j<=m;++j)write(ans[j][i]),push(' ');
push('\n');
}
flush();
return 0;
}
【cf contest 1119 G】Get Ready for the Battle的更多相关文章
- 【cf contest 1119 H】Triple
题目 给出 \(n\) 个三元组\(\{ a_i,b_i,c_i \}\)和\(x,y,z\): 将每个三元组扩展成(\(x\)个\(a_i\),\(y\)个\(b_i\),\(z\)个\(c_i\) ...
- 【codeforces contest 1119 F】Niyaz and Small Degrees
题目 描述 \(n\) 个点的树,每条边有一个边权: 对于一个 \(X\) ,求删去一些边后使得每个点的度数 \(d_i\) 均不超过 \(X\) 的最小代价: 你需要依次输出 \(X=0 \to n ...
- 【Cf Edu #47 G】Allowed Letters
这个题大概就是每一个位置都有一个能填字符的限制(一个点集),给出已有的$n$个字符,问能填出的最小字典序的字符串. 总体思路是贪心,每一位尽量选最小的字符. 关键在于判断在某位选了一个字符后,接下来的 ...
- B. Lost Number【CF交互题 暴力】
B. Lost Number[CF交互题 暴力] This is an interactive problem. Remember to flush your output while communi ...
- 【CF contest/792/problem/E】
E. Colored Balls time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 【CF edu 27 G. Shortest Path Problem?】
time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standa ...
- 3.26-3.31【cf补题+其他】
计蒜客)翻硬币 //暴力匹配 #include<cstdio> #include<cstring> #define CLR(a, b) memset((a), (b), s ...
- 【cf补题记录】Codeforces Round #608 (Div. 2)
比赛传送门 再次改下写博客的格式,以锻炼自己码字能力 A. Suits 题意:有四种材料,第一套西装需要 \(a\).\(d\) 各一件,卖 \(e\) 块:第二套西装需要 \(b\).\(c\).\ ...
- 【郑轻邀请赛 G】密室逃脱
[题目链接]:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2133 [题意] [题解] 考虑每一个二进制数的最高位->第i位; 肯定是1(这 ...
随机推荐
- angular复习笔记2-架构总览
angular架构总览 一个完整的Angular应用主要由6个重要部分构成,分别是:组件.模板.指令.服务.依赖注入和路由.这些组成部分各司其职,而又紧密协作,它们的关系如图所示. 与用户直接交互的是 ...
- vue插件(还真是第一次接触)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Synchronized可重入锁分析
可重入锁又称递归锁,是指在同一个线程在外层方法获取锁的时候,再进入该线程的内层方法会自动获取锁(前提是锁对象必须是同一对象或者class), 不会因为之前已经获取过还没实方而发生阻塞.即同一线程可执行 ...
- 【体系结构】有关Oracle SCN知识点的整理
[体系结构]有关Oracle SCN知识点的整理 1 BLOG文档结构图 BLOG_Oracle_lhr_Oracle SCN的一点研究.pdf 2 前言部分 2.1 导读和注意事项 各位技 ...
- linux下的 c 和 c++ 开发工具及linux内核开发工具
https://opensource.com/article/18/6/embedded-linux-build-tools https://github.com/luong-komorebi/Awe ...
- 【问题】如何在Linux与Windows间共享文件
实验环境 Linux LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: CentOS Description: CentOS L ...
- java集合-遍历arraylist-for循环-从指定下标开始遍历-for的用法
转载:http://www.9191boke.com/blogdetails/681220549.html java集合的for循环遍历有多种方式,但是都是从下标0开始遍历,有时会有从中间下标开始遍历 ...
- [转载]Mysql数据库千万级数据处理优化
转载:http://blog.sina.com.cn/s/blog_6dcd17320100tm6o.html 1. 对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by ...
- web安全漏洞相关
1,密码输入框input应该 设置:autocompete="off" 2,设置HTTPOnly,禁止客户端修改cookie 文章:Cookie中的HttpOnly详解 3,不要展 ...
- SQL进阶系列之12SQL编程方法
写在前面 KISS -- keep it sweet and simple 表的设计 注意命名的意义 英文字母 + 阿拉伯数字 + 下划线"_" 属性和列 编程的方针 写注释 注意 ...