链接:https://codeforces.com/contest/1282/problem/C

题意:  有一个人参加考试,考试只有两种题,一种是简单题,每道题耗时固定为a;另一种是困难题,每道题耗时固定为b,保证b>a。解出一道题得分都是1。考试的规则并不只是写多少题得多少分,鼓励提前交卷。假如你没有提前交卷,那么有一部分的题目会列为“必做题”,当“必做题”的题目没有全部被完成的话,这门课就算0分;否则得到与题数相同的分数,包括“必做”和“非必做”的。

题意: 题意很明显需要按题目的“必做时间”按照升序排列起来,然后贪心着做,从头开始遍历每道题目的必做时间。假如遍历到第i个题了,当前时间为T,那么如果在T-1时刻交卷,首先需要把前面必须做的所有题目做完,假设这个过程花费了Ti时间,然后剩下了T - Ti的时间,那么我们就在剩下的时间内贪心着先做尽可能多剩余的简单题,再做难题,记录此时的ans,不断遍历所有题目的必须做时间到最后,也不断的更新ans的最大值。最终的ans就是答案

AC代码:

 #include<iostream>
#include<string>
#include<vector>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1e9+;
const int maxn = 2e5+;
struct node{
int dif;
int ti;
}g[maxn];
bool cmp(node a,node b){
if(a.ti !=b.ti ) return a.ti<b.ti ;
return a.dif <b.dif ;
}
int main(){
int q;cin>>q;
while(q--){
ll n,t,a,b;
cin>>n>>t>>a>>b;
ll cnta = ,cntb = ;
for(int i = ;i<=n;i++){
int Td;cin>>Td;
if(Td == ) cnta++;
else cntb++;
g[i].dif = Td;
}
for(int i = ;i<=n;i++){
int T;cin>>T;
g[i].ti = T;
}
sort(g+,g+n+,cmp);//按必做时间先排序
g[n+].ti = t+;
ll ans = ,c1 = ,c2 = ;//c1 c2统计必做题目的个数
for(int i = ;i<=n+;i++){
ll cur = a*c1 + b*c2;
ll time = g[i].ti - - cur;//必做题目花费的时间
if(time>=){//如果有多余的时间,那么尽可能做更多的简单题,再做难题
ll ta = min(time/a,cnta-c1);
time-=ta*a;
ll tb = min(time/b,cntb-c2);
ans = max(ans,c1+c2+ta+tb);
}
if(g[i].dif == ) c1++;
else c2++;
}
cout<<ans<<endl;
}
return ;
}

codeforces 1282C. Petya and Exam (贪心)的更多相关文章

  1. CodeForces 832B Petya and Exam

    B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  2. Codeforces Round #425 (Div. 2) B. Petya and Exam(字符串模拟 水)

    题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds mem ...

  3. Codeforces Round #425 (Div. 2) B - Petya and Exam

    地址:http://codeforces.com/contest/832/problem/B 题目: B. Petya and Exam time limit per test 2 seconds m ...

  4. E - Petya and Exam CodeForces - 832B 字典树+搜索

    E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...

  5. B. Petya and Exam

    B. Petya and Exam 题目链接 题意 给你一串字符,在这个串中所有出现的字符都是\(good\)字符,未出现的都是\(bad\)字符, 然后给你另一串字符,这个字符串中有两个特殊的字符, ...

  6. CodeForces832-B. Petya and Exam

    补的若干年以前的题目,水题,太菜啦_(:з」∠)_    B. Petya and Exam time limit per test 2 seconds memory limit per test 2 ...

  7. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  8. Codefroces 832B Petya and Exam

    B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  9. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

随机推荐

  1. 【39】为什么使用卷积?(Why convolutions?)

    为什么使用卷积?(Why convolutions?) 我们来分析一下卷积在神经网络中如此受用的原因,然后对如何整合这些卷积,如何通过一个标注过的训练集训练卷积神经网络做个简单概括.和只用全连接层相比 ...

  2. Python3中的支持向量机SVM的使用(有实例)

    https://www.cnblogs.com/luyaoblog/p/6775342.html 首先,我们需要安装scikit-learn 一.导入sklearn算法包  在python中导入sci ...

  3. NodeJS_0001:关于install的方式

    最近在写Node程序的时候,突然对 npm install 的-save和-save-dev 这两个参数的使用比较混乱.其实博主在这之前对这两个参数的理解也是模糊的,各种查资料和实践后对它们之间的异同 ...

  4. 在 Node 中使用 formidable 处理文件上传

    具体使用方式参照官方文档:https://www.npmjs.com/package/formidable 第一:安装: # npm install --save formidable yarn ad ...

  5. Arcgis runtime sdk .net 二次开发

    前段时间研究了下 arcgis runtime sdk .net 二次开发··这里做个笔记 runtime版本为100.6 基于WPF 开发 命名空间引入 xmlns:esri="http: ...

  6. WPF Dispatcher.BeginInvoke子线程更新UI

    在开发WPF应用时出现:”调用线程无法访问此对象,因为另一个线程拥有该对象.“ 是因为UI线程是WPF应用的主线程,若尝试子线程更新UI线程应使用Dispatcher.BeginInvoke()或者I ...

  7. react-发表评论案例

    评论列表组件 import React from 'react' import CMTItem from './CmtItem.jsx' import CMTBox from './CmtBox.js ...

  8. php redis使用

    访问连接 远程访问 //实例化 $redis=new Redis(); try{ $redis->connect('47.98.55.11','6379'); $redis->auth(' ...

  9. gulp-css-spriter 雪碧图合并

    相信做前端的同学都做过这样的事情,为优化图片,减少请求会把拿到切好的图标图片,通过ps(或者其他工具)把图片合并到一张图里面,再通过css定位把对于的样式写出来引用的html里面.gulp-css-s ...

  10. centos因为安装花生壳而无法登录系统的问题

    服务器安装 phddns 花生壳 启动失败,一直卡在启动进度条页面. 解决办法 1.按F5查看卡在什么位置, 2.查看解决方法:程序卡住的情况下,直接备份资料后,卸载程序重启就可以了. 3.进入到si ...