codeforces 1282C. Petya and Exam (贪心)
链接: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 (贪心)的更多相关文章
- CodeForces 832B Petya and Exam
B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 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 ...
- 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 ...
- E - Petya and Exam CodeForces - 832B 字典树+搜索
E - Petya and Exam CodeForces - 832B 这个题目其实可以不用字典树写,但是因为之前写过poj的一个题目,意思和这个差不多,所以就用字典树写了一遍. 代码还是很好理解的 ...
- B. Petya and Exam
B. Petya and Exam 题目链接 题意 给你一串字符,在这个串中所有出现的字符都是\(good\)字符,未出现的都是\(bad\)字符, 然后给你另一串字符,这个字符串中有两个特殊的字符, ...
- CodeForces832-B. Petya and Exam
补的若干年以前的题目,水题,太菜啦_(:з」∠)_ B. Petya and Exam time limit per test 2 seconds memory limit per test 2 ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- Codefroces 832B Petya and Exam
B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
随机推荐
- 深入浅出Mybatis系列十-SQL执行流程分析(源码篇)
注:本文转载自南轲梦 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 最近太忙了,一直没时间继续更新博客,今天忙里偷闲继续我的Mybatis学习之旅.在前 ...
- 组件使用v-model、$listeners、.sync(区别于v-model的双向数据绑定)
自定义组件 自定义组件的v-model 首先我们先说一下在自定义组件中使用v-model的必要条件 在自定义的组件中要有input(这里我们先不讨论单选复选框) 在自定义组件的模板对象中要有props ...
- java简单验证码生成程序
下面的函数,返回的字符串就是所需验证码 public String id(){ Random ra =new Random(); st=""; String [] w= {&quo ...
- JavaDay7(下)
问题1描述 编写一个方法,返回一个double类型二维数组,数组中的元素通过解析字符串参数获得. 代码实现: public class ArrayParser { public static void ...
- python计算文件大小
1.使用到的语句 import os 库 os.listdir(path) 返回文件名字符串列表 os.path.isdir(path) 判断文件名是否是文件夹 os.path.getsize(pat ...
- 牛客寒假训练营2-H施魔法
思路 dp去维护前缀f[i-1] - ai的最小值 CODE #include <bits/stdc++.h> #define dbg(x) cout << #x <&l ...
- bootstrap-table中时间戳转换为日期格式。
{ field: 'createdTime', title: '创建时间', formatter: function (value, row, index) { return changeDateFo ...
- Android学习笔记(一)
目录 Android学习笔记(一) 一.JDK.Android SDK 二.部分项目结构 三.字符串引用 四.外层build.gradle详解 五.app->build.gradle详解 六.日 ...
- js - 除法
取整数 1.丢弃小数部分,保留整数部分 js:parseInt(7/2) 2.向上取整,有小数就整数部分加1 js: Math.ceil(7/2) 3,四舍五入. js: Math.round(7/2 ...
- 1级搭建类111-Oracle 19c SI FS(Windows Server 2019)公开
Oracle 19c 单实例文件系统在Windows Server 2019上的安装 在线查看