Codeforces Round #133 (Div. 2) C. Hiring Staff 想法题目
http://codeforces.com/problemset/problem/216/C
题意:
在Berland法律规定每个工人的工作是这样的:它必须连续工作n天,然后休息m天,然后才能继续工作n天休息m天也即他的工作时间为[x, x + 1, ..., x + n - 1], [x + m + n, x + m + n + 1, ..., x + m + 2n - 1] Vitaly的工场必须保证每天有k个工人,而且还要保证在第n天时,有员工能够接任工厂钥匙。Vitaly想尽量少的雇用工人,以减少花费。求他最少雇用员工的个数以及他们分别在第几天雇用。
思路:
自己开了虚拟比赛做的题目,好不容易把A,B做完了来整这道题,分析了很久,云里雾里脑子乱的很。所以就没推出来,赛后看了官方的解体报告。觉得这种想法太好了。自己脑子还是比较笨。
The second solution: greedy.
Let's create an array where we will store current number of employees for some number of the first days. Now you should iterate over all days from the first to the n + m-th and hire employees every time when it needed. You should hire workers if there are less than kpeople in the current day; also you should hire worker if there will be no people tomorrow (thet worker will bring the key to the workers that will work tomorrow).
This solution works in O((n + m)k).
This solution also works correctly for cases n < m, but then it has bigger complexity and requires more time.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <map> #include <string>#define CL(a,num) memset((a),(num),sizeof(a)) #define iabs(x) ((x) > 0 ? (x) : -(x)) #define Min(a,b) (a) > (b)? (b):(a) #define Max(a,b) (a) > (b)? (a):(b)#define ll long long #define inf 0x7f7f7f7f #define MOD 1073741824 #define lc l,m,rt<<1 #define rc m + 1,r,rt<<1|1 #define pi acos(-1.0) #define test puts("<------------------->") #define maxn 100007 #define M 1000007 #define N 20007 using namespace std; //freopen("data.in","r",stdin);int use[N]; vector<int>vi; int main(){// freopen("data.in","r",stdin);int n,m,k;int i,j;while (~scanf("%d%d%d",&n,&m,&k)){CL(use,0); vi.clear();for (i = 1; i <= m + n; ++i){/*use记录每一天雇用的人数,必须保证每天的人数>=k并且在第n天时要加进人来拿钥匙。我们只要枚举出1到m + n时的一个循环就好,以后就是每m + n + x个一个循环,这里应该有+x的*/while (use[i] < k || *(vi.rbegin()) + n - 1 == i){vi.push_back(i);for (j = i; j <= i + n - 1; ++j) use[j]++;}}printf("%d\n",vi.size());vector<int>::iterator it;for (it = vi.begin(); it != vi.end(); ++it){if (it == vi.end() - 1)printf("%d\n",*it);elseprintf("%d ",*it);}}return 0; }
转载于:https://www.cnblogs.com/E-star/archive/2012/10/25/2739977.html
Codeforces Round #133 (Div. 2) C. Hiring Staff 想法题目相关推荐
- Codeforces Round #645 (Div. 2) D. The Best Vacation
Codeforces Round #645 (Div. 2) D. The Best Vacation 题目链接 You've been in love with Coronavirus-chan f ...
- Codeforces Round #738 (Div. 2) A--D1
原题戳这里Codeforces Round #738 (Div. 2) A. Mocha and Math 题目大意 通过对某个区间内的数进行题目所给操作 希望最小化序列中的最大值 思路 万恶的位运算 ...
- Codeforces Round #706 (Div. 2)B. Max and Mex
Codeforces Round #706 (Div. 2)B. Max and Mex 题目 题目大意 刚开始给你n个不同的数,k次询问每次求在该序列中已存在的最大的数和不存在的最小的数(大于等于零 ...
- Codeforces Round #644 (Div. 3) G.A/B Matrix
Codeforces Round #644 (Div. 3) G.A/B Matrix 题目链接 You are given four positive integers n, m, a, b (1≤ ...
- Codeforces Round #662 (Div. 2) B. Applejack and Storages
Codeforces Round #662 (Div. 2) B. Applejack and Storages 题目链接 This year in Equestria was a year of p ...
- Codeforces Round #739 (Div. 3) 「A B C D E F1 F2」
Codeforces Round #739 (Div. 3) A. Dislike of Threes 题目描述: 如果一个数能被3整除或者十进制结尾的数字是3则是无趣的数,你想知道第n个有趣的数是什 ...
- Codeforces Round #636 (Div. 3) D.Constant Palindrome Sum
Codeforces Round #636 (Div. 3) D.Constant Palindrome Sum 题目链接 You are given an array a consisting of ...
- Educational Codeforces Round 133 (Rated for Div. 2)(CD题解)
Educational Codeforces Round 133 (Rated for Div. 2)CD题解 过AB补CD C. Robot in a Hallway 题意 题意:现有 2∗m 的方 ...
- Educational Codeforces Round 133 (Rated for Div. 2) 题解 CD
D: 这是一道好dp(对我来说) 我做的时候有想过正解那个方式当考虑到可能有重复就没有深入思考了 假设dp[i][j]代表第i次j的方案数 此时我们可以发现dp[i][j]=sum(dp[i-1][j ...
最新文章
- vs2017通过snippet代码片断进行标准化注释
- 密码登录源码(jsp+java+数据库)
- Imageio: 'ffmpeg-win32-v3.2.4.exe' was not found on your computer; downloading it now.
- 实例对象静态对象实例方法静态方法
- linux计算脚本执行时间,linux – 计算shell脚本每一步的时间并显示总执行时间
- Codeup-问题 A: 最大连续子序列
- OpenCV学习笔记十一-findcounters函数
- Linux 串口编程四 串口设备程序开发
- 牛客13584 日历中的数字
- html传输的数值表示的含义,数字传递游戏的意义与感悟_传数字游戏心得体会
- Julia面向对象(多重派发)
- ICLR2019 | 模型训练会发生了大量的、反复的样本遗忘现象,如何解决?
- Linux iptables防火墙详解(二)——iptables基本配置
- 《那些年啊,那些事——一个程序员的奋斗史》七
- linux系统 如何选择题,Linux考证试题选择题
- 如何快速的切换EXCEL
- 如何设置qq说说展示时间_qq说说可以设置时间
- mysql 1033 Incorrect information in file 错误
- origin出图重合部分变色了,怎么办?
- php北京平均工资,2016年北京平均工资是多少?
热门文章
- 2017-9-17pat甲级 A
- python有限循环_Python循环
- Hyperledger Fabric 1.0 实战开发系列 第一课 系统环境搭建
- Android自定义控件实现九宫格解锁
- 主板rs232接口测试软件,简洁的RS232串口通信电路与串口通信测试程序
- 如何用python把xlsx变为csv_python将excel转换为csv的代码方法总结
- wpf将文字转化为图形_工程师们开发出将天然气转化为固体的方法
- java 初始化一个实体对象_Java 对象初始化
- CCF OJ 1113-括号匹配[栈]
- A*B Problem