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题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
随机推荐
- AOV拓扑排序实验-2-AOV类的实现
下面是这个类的实现代码: //这只是一个基本的框架,没有封装 #include<iostream> #include<cstdio> #include<malloc.h& ...
- 安装MongoDB到Ubuntu(APT)
运行环境 系统版本:Ubuntu 16.04.5 LTS 软件版本:mongodb-org-4.0.8 硬件要求:无 安装过程 1.配置APT-Mongodb存储库 ATP-Mongodb存储库由Mo ...
- 使用SMTP协议发送邮件
class Program { static void Main(string[] args) { ) { try { inputmodel obj = new inputmodel(args); S ...
- Nessus 8.2.3无IP限制VM版虚拟机
根据“西门吹雪”http://ximcx.cn/m/?post=151的文章自己下载配置的过程 VM版本>=12都行,我用的是VM14 下载地址 https://moehu-my.sharepo ...
- 树莓派查看ip地址(命令ifconfig)和退出ping
1.1树莓派查看ip地址用如下命令: ifconfig -a 结果如下图所示: 注意:树莓派查看ip地址是用命令ifconfig,而Windows的cmd命令查看ip地址是ipconfig.
- js数据类型1
1. 分类(2大类) 基本(值)类型--5种 Number: 任意数值 String: 任意文本 Boolean: true/false undefined: undefined null: null ...
- 配置webpack中dev.env.js、prod.env.js,解决不同命令下项目启动和打包到指定的环境
前后端分离的项目开发中,我们有开发环境.测试环境.预生产环境和生产环境. 1.开发环境下调试接口的时候,一般都会有好几个接口地址(开发服务器上的,本地的,接口开发人员的,七七八八的接口地址),要根据情 ...
- Linux vim三种模式的快捷键
1.移动光标 数字 + h,j,k,l 上,下,左,右 ctrl-e 移动页面 ctrl-f 上翻一页 ctrl-b 下翻一页 ctrl-u 上翻半页 ctrl-d 下翻半页 w 跳到下一个字首,按标 ...
- 深入浅出Mybatis系列四-配置详解之typeAliases别名(mybatis源码篇)
注:本文转载自南轲梦 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 上篇文章<深入浅出Mybatis系列(三)---配置详解之properties ...
- qsort 与sort 对结构体排序实例
qsort 与sort 对结构体排序实例 #include<bits/stdc++.h> using namespace std; typedef struct { string book ...