Exams(二分
题意:给你每天要考的科目,和每门科目需要复习多长时间,问最少需要几天才能完成所有的考试。
思路:二分答案,然后判断答案是否可行,这边需要进行贪心,即倒着往前推,
比如第i天,那么前面有i-1天是,可供复习的时间是i-1-还有几门科目要考(不包括自己),然后进行判断。。。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define se second
#define fi first
const int INF= 0x3f3f3f3f;
const int N=1e5+; int n,m,cnt=;
int a[N],b[N],book[N]={},loc[N]; bool check(int day)
{
memset(book,,sizeof(book)); //每次都要清空。。WA点
int exam=m;
book[]=; //漏了。。
for(int i=day;i>=;i--)
{
if( book[a[i]]== )
{
if( i- >= (b[a[i]] + exam-) ) //可以复习的天数>=当前科目需要复习的天数+前面考试的天数
{
//cout<<i-1<<endl;
book[a[i]]=;
exam--;
}
else return ;
}
if(exam==) break;
}
if(exam==) return ;//
else return ;
} int main()
{
int l=,mid,r;
cin>>n>>m;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=;i<=m;i++){
scanf("%d",&b[i]);
l+= (b[i]+) ; //复习的天数+考试的一天
}
r=n;
int ans=-;
while(l<=r)
{
mid=(l+r)>>;
if( check(mid) ){
r=mid-;
ans=mid;
}
else l=mid+;
}
if(l>n) cout<<-;
else cout<<l;
}
Exams(二分的更多相关文章
- CF732D. Exams[二分答案 贪心]
D. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #377 (Div. 2) D. Exams(二分答案)
D. Exams Problem Description: Vasiliy has an exam period which will continue for n days. He has to p ...
- Codeforces Round #377 (Div. 2) D. Exams 二分
D. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- CodeForces 732D Exams (二分)
题意:某人要考试,有n天考m个科目,然后有m个科目要考试的时间和要复习多少天才能做,问你他最早考完所有科目是什么时间. 析:二分答案,然后在判断时,直接就是倒着判,很明显后出来的优先,也就是一个栈. ...
- CF732D Exams 二分 贪心
思路:二分+贪心 提交次数:10次以上 错因:刚开始以为二分(边界,$+1or-1$)写错了,调了半天,后来才发现是$ck()$写错了.开始只判了最后是否小于零,而应该中间一旦小于零就$return\ ...
- cd732D Exams 二分
题目:http://codeforces.com/problemset/problem/732/D 题意:给你n,m,n个数,m个数,n天,m场考试,给出n天每天能考第几场考试(如果是0则那天考不了试 ...
- 二分算法题目训练(二)——Exams详解
CodeForces732D——Exams 详解 Exam 题目描述(google翻译) Vasiliy的考试期限将持续n天.他必须通过m门科目的考试.受试者编号为1至m. 大约每天我们都知道当天可以 ...
- 【CF732D】Exams(线性扫描,贪心,二分)
题意:有m门需要过的课程,n天的时间可以选择复习.考试(如果的d[i]为0则只能复习),一门课至少要复习a[i]天才能通过(可以不连续的复习得到a[i]),问最早什么时候可以把所有课程都通过,如果不能 ...
- Exams
Exams time limit per test 1 second memory limit per test 256 megabytes input standard input output s ...
随机推荐
- 【Kail 学习笔记】自用KAIL更新源
打开 /etc/apt/source.list 添加-保存即可 deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contr ...
- Flutter状态管理Provider,简单上手
在之前的文章中介绍了 Google 官方仓库下的一个状态管理 Provide.乍一看这俩玩意可能很容易就被认为是同一个东西,仔细一看,这不就差了一个字吗,有什么区别呢. 首先,你要知道的最大的一个区别 ...
- 在MAC上安装gitlab
转载引用:https://www.cnblogs.com/floodwater/p/10138265.html 1.安装docker 2.安装gitlab-ce 1.安装docker 下载地址: ht ...
- [转帖]前端 crypto-js aes 加解密
前端 crypto-js aes 加解密 2018.04.13 11:37:21字数 891阅读 59767 https://www.jianshu.com/p/a47477e8126a 原来前端也有 ...
- Windows Terminal Preview v0.7 Release
Windows Terminal Preview v0.7 Release The following key bindings are included by default within this ...
- 公式编辑器之 AxMath(18)
1. 使用教程 视频教程,一共有18集,每集都比较短. >> 视频教程链接:B站,速度快,清晰 2. 破解软件下载链接 >> 下载链接:复制链接到迅雷或IDM下载很快 3. M ...
- 开源定时任务框架Quartz(一)
简介 Quartz是OpenSymphony开源组织的一个开源项目,定时任务框架,纯Java语言实现,最新版本为2.3.0. 设计模式 Quartz中使用的设计模式如下: 1.Builder模式 2. ...
- GB2312、GBK、GB18030 这几种字符集的主要区别
1 GB2312-80 GB 2312 或 GB 2312-80 是中国国家标准简体中文字符集,全称<信息交换用汉字编码字符集·基本集>,又称 GB 0,由中国国家标准总局发布,1981 ...
- LIUNX随堂学习-3 权限
1.权限分为三类:读r,写w,执行x 2.读r:可以ls改目录下的子文件名,子目录名 写w:可以在该目录下创建.删除.重命名 执行x:可以cd到该目录下 3. ll (ls -l) 下详细信息的意义 ...
- MongoDB部分