codechef july月赛 Chef's Dream
来源:互联网 发布:java精品课程网站 编辑:程序博客网 时间:2024/05/21 12:43
Chef's Dream
Problem code: DREAM
All submissions for this problem are available.
The Chef is sleeping now. He tries to cook new kind of meals in his dream.
These meals are arranged in a row and numbered from 1 to N consecutively. For each meali (1<=i<=N) there is given one integer f(i) which denotes the time needed to cook it. Initially, all meals are uncooked. Each assistant of The Chef (there are infinite number of them) can help him with cooking.
The abilities of all assistants are same. There can be at most one assistant cooking at each moment. He must choose some continuous subsequence of meals with lengthK(any such subsequence can be chosen). And if there are uncooked meals in it, he will cook all uncooked meals which has the minimum cooking time among uncooked meals in the chosen subsequence. Nothing done to another meals.
The dream was so interesting that he tried to solve such a problem: What is the minimum number of assistants which can cook all the meals assuming that each of them will cook at most once? But since the bell rings and Chef's friends has come to visit him, he will wake up after 2 seconds. Your program should calculate the answer before The Chef will come to himself.
Input
First line of input file contains two integers N (1<=N<=105) andK (1<=K<=N), followed by a line containingN integers. The ith integer denotes f(i)-the cooking time of meal numberi (1<=f(i)<=109)
Output
Print minimum number of assistans which can cook all the meals in one line.
Example
Input:5 340 30 40 30 40Output:3
Explanation:
3 assistants are enough to cook all the meals. They can work in following schedule:
1st assistant chooses interval [2,4] and cooks meals 2 and 4.
2nd assistant chooses interval [1,3] and cooks meals 1 and 3.
3rd assistant chooses interval [3,5] and cooks meal 5.
Other schedules can also be possible.
题意: 输入n k n个数 区间长度k
然后每次在区间内把最小的数标记 问所有的都标记后要多少次
/*我一开始拿到这道题 手无足措不知道该如何下手 这种题千万注意 一定要多写几组数据 认真研究如果多写几组数据就会发现如下规律*/#include <iostream>#include <map>#include <cstdio>using namespace std;const int sz=200200;int B[sz],N,K,ans;map<int,bool> hm;int main(){int f;scanf("%d%d",&N,&K);for(int i=1;i<=N;i++){scanf("%d",&f);if(!hm[f])//超级帅 把复杂度降低到了log(n),方法很巧妙{hm[f]=true; ans++; B[i+K-1]=f;}hm[B[i]]=false;}for(i=1;i<=N;i++) printf("%d\n",B[i]);printf("%d\n",ans);return 0;}
- codechef july月赛 Chef's Dream
- codechef july月赛 The Gray-Similar Code
- CodeChef Chef and Segments
- codechef Chef and sequence
- codechef Chef and Swaps
- Codechef Chef and Reversing
- Codechef Chef and Frogs
- Codechef Chef and Churu
- 【CodeChef】 Chef and Stones
- 【CodeChef】Chef and Interview
- codechef Chef and Churu
- codechef July Challenge 2014
- [多维FFT Bluestein′s Algorithm] Codechef October Challenge 2017 .Chef and Horcrux
- codechef Chef and easy problem
- codechef Chef and Left-Right
- codechef-Chef and Prime Divisors
- CodeChef Chef and Strange Operations
- Chef and Graph Queries (codechef)
- 黄金点游戏
- NYOJ 21 图的广度优先搜索 倒水问题
- 高质量Android 代码
- 数据结构实验之链表五:单链表的拆分
- 自己对与螺旋矩阵算法的一些见解
- codechef july月赛 Chef's Dream
- SQL2005备份集中的数据库备份与现有的数据库不同,错误号码:3154,解决方法
- myeclipse安装svn插件的多种方式
- linux shell 判断IP 是否合法
- 每天工作4小时的程序员
- UVA 11991
- IOS6用xib在5.0模拟器中运行
- ubuntu 设置环境变量
- It Was a Good Barn