zoukankan      html  css  js  c++  java
  • 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代码:

     1 #include<iostream>
     2 #include<string>
     3 #include<vector>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<algorithm>
     7 using namespace std;
     8 typedef long long ll;
     9 ll mod = 1e9+7;
    10 const int maxn = 2e5+10;
    11 struct node{
    12     int dif;
    13     int ti;
    14 }g[maxn];
    15 bool cmp(node a,node b){
    16     if(a.ti !=b.ti ) return a.ti<b.ti ;
    17     return a.dif <b.dif ; 
    18 }
    19 int main(){
    20     int q;cin>>q;
    21     while(q--){
    22         ll n,t,a,b;
    23         cin>>n>>t>>a>>b;
    24         ll cnta = 0,cntb = 0;
    25         for(int i = 1;i<=n;i++){
    26             int Td;cin>>Td;
    27             if(Td == 0) cnta++;
    28             else cntb++;
    29             g[i].dif = Td;
    30         }
    31         for(int i = 1;i<=n;i++){
    32             int T;cin>>T;
    33             g[i].ti = T;
    34         }
    35         sort(g+1,g+n+1,cmp);//按必做时间先排序
    36         g[n+1].ti = t+1;
    37         ll ans = 0,c1 = 0,c2 = 0;//c1 c2统计必做题目的个数
    38         for(int i = 1;i<=n+1;i++){
    39             ll cur = a*c1 + b*c2;
    40             ll time = g[i].ti - 1 - cur;//必做题目花费的时间
    41             if(time>=0){//如果有多余的时间,那么尽可能做更多的简单题,再做难题
    42                 ll ta = min(time/a,cnta-c1);
    43                 time-=ta*a;
    44                 ll tb = min(time/b,cntb-c2);
    45                 ans = max(ans,c1+c2+ta+tb);
    46             }
    47             if(g[i].dif == 0) c1++;
    48             else c2++;
    49         }
    50         cout<<ans<<endl;
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    如何在XSLT中实现勾选的效果
    6个jQuery图表Web应用扩展
    数据仓库(集市)之间共享维度表
    Json.NET
    jquery调用页面的方法
    使用javascript打开模态对话框
    使用ApplicationDeployment 类以编程方面对ClickOnce程序进行更新 【转载】
    XSLT 编译器 (xsltc.exe)
    在xslt中添加链接的方式
    哀悼
  • 原文地址:https://www.cnblogs.com/AaronChang/p/12130163.html
Copyright © 2011-2022 走看看