Codeforces Round #133 (Div. 2) C. Hiring Staff 想法题目
http://codeforces.com/problemset/problem/216/C
題意:
在Berland法律規(guī)定每個工人的工作是這樣的:它必須連續(xù)工作n天,然后休息m天,然后才能繼續(xù)工作n天休息m天也即他的工作時間為[x,?x?+?1,?...,?x?+?n?-?1],?[x?+?m?+?n,?x?+?m?+?n?+?1,?...,?x?+?m?+?2n?-?1]?Vitaly的工場必須保證每天有k個工人,而且還要保證在第n天時,有員工能夠接任工廠鑰匙。Vitaly想盡量少的雇用工人,以減少花費。求他最少雇用員工的個數(shù)以及他們分別在第幾天雇用。
思路:
自己開了虛擬比賽做的題目,好不容易把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.
?
View Code #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記錄每一天雇用的人數(shù),必須保證每天的人數(shù)>=k并且在第n天時要加進人來拿鑰匙。我們只要枚舉出1到m + n時的一個循環(huán)就好,以后就是每m + n + x個一個循環(huán),這里應該有+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; }?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/E-star/archive/2012/10/25/2739977.html
總結(jié)
以上是生活随笔為你收集整理的Codeforces Round #133 (Div. 2) C. Hiring Staff 想法题目的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [1025]Noip 2009 Prob
- 下一篇: EXT 删除 监听