链接: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. SP7258 SUBLEX - Lexicographical Substring Search - 后缀自动机,dp

    给定一个字符串,求本质不同排名第k小的子串 Solution 后缀自动机上每条路径对应一个本质不同的子串 按照 TRANS 图的拓扑序,DP 计算出每个点发出多少条路径 (注意区别 TRANS 图的拓 ...

  2. Process、管理者权限、注册表、xml修改

    //判断是否有管理者权限 WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); if (!p ...

  3. STM32学习笔记 —— 0.1 Keil5安装和DAP仿真下载器配置的相关问题与注意事项

    Keil5安装的注意事项 安装细节在此不再做过多赘述,主要介绍一下注意事项: 安装路径中不能有中文. ARM的Keil的路径不能与51的Keil的有冲突,必须将目录分开. Keil5中不会自动添加芯片 ...

  4. LOJ #3119. 「CTS2019 | CTSC2019」随机立方体 组合计数+二项式反演

    好神的一道计数题呀. code: #include <cstdio> #include <algorithm> #include <cstring> #define ...

  5. P6070 [RC-02] GCD [杜教筛,莫比乌斯反演]

    没啥好说的,杜教筛板子题. \[\sum_{i=1}^{N} \sum_{j=1}^{N}\sum_{p=1}^{\lfloor \frac{N}{j} \rfloor}\sum_{q=1}^{\lf ...

  6. python里的复数complex

    复数是一个数学概念,包含了实部和虚部.在python设计语言中,可以直接定义以j为单位,也可以使用complex函数创建复数,这个函数可以传实部和虚部,也可以只传实部. 我们把形如z=a+bj(a,b ...

  7. int long的数据范围

    java 整数型 byte 1字节   -128~127  -2^7~2^7-1 short 2字节 -32768~32767 int  4个字节 -2147483648~2147483647  -2 ...

  8. Progressbar 实例

    Progressbar 实例原创侠之大者为国为民 最后发布于2015-10-28 15:22:34 阅读数 5394 收藏展开Progressbar - orient 配置进度条的方向:"h ...

  9. php 对接国外支付 ipay88支付

    ipay88支付 近期接了一个国外的项目,客户指定要这种支付,就搞搞呗,其实流程和思路都是差不多的,往下看 他的流程其实非常简单  下面的流程仔细看看,看懂了就会了 1 首先我们需要先获取下单所需要的 ...

  10. c++ 踩坑大法好 复合数据类型------vector

    1,vector是啥? 是具有动态大小的数组,具有顺序.能够存放各种类型的对象.相比于固定长度的数组,运行效率稍微低一些,不过很方便. 2,咋用? 声明: vector <int> vi; ...