1. 程式人生 > >【BZOJ4868】期末考試 [三分][貪心]

【BZOJ4868】期末考試 [三分][貪心]

sof col math ems lose discuss com std pan

期末考試

Time Limit: 20 Sec Memory Limit: 512 MB
[Submit][Status][Discuss]

Description

  技術分享

Input

  技術分享

Output

  技術分享

Sample Input

  100 100 2
  4 5
  5 1 2 3
  1 1 2 3 3

Sample Output

  6

HINT

  技術分享

Solution

  首先,由於學生需要知道所有的成績,這意味著即使只有一個成績不知道,代價也是要算的,那麽顯然答案只和所有成績都發出的時間有關。
  顯然,如果我們知道了所有成績都發出的時間,必然是可以算出最小的不愉快度

的,對於一個最後日期x,我們運用貪心得到不愉快度:
    1.由於A策略有負面影響,B策略沒有,所有在A<B的情況下才有可能用A
    2.如果我們需要用A,顯然能用的次數是:所有天數在x前面的 (x-天數),剩下的用B補滿。
  然後,我們大膽猜測可以三分!這樣我們就能AC啦。

Code

技術分享
 1 #include<iostream>  
 2 #include<string>  
 3 #include<algorithm>  
 4 #include<cstdio>  
 5 #include<cstring>  
 6
#include<cstdlib> 7 #include<cmath> 8 using namespace std; 9 typedef long long s64; 10 11 const int ONE = 1000001; 12 const s64 INF = 1e18; 13 14 int A,B,C,n,m; 15 int t[ONE],b[ONE],MaxN; 16 s64 Ans = INF; 17 int Now; 18 19 inline s64 get() 20 { 21 s64 res=1,Q=1
; char c; 22 while( (c=getchar())<48 || c>57) 23 if(c==-)Q=-1; 24 if(Q) res=c-48; 25 while((c=getchar())>=48 && c<=57) 26 res=res*10+c-48; 27 return res*Q; 28 } 29 30 s64 Judge(s64 x) 31 { 32 s64 res = 0, num1 = 0, num2 = 0; 33 for(int i=1;i<=n;i++) res += max(x-t[i],0LL) * C; 34 for(int i=1;i<=m;i++) num1 += max(x-b[i],0LL), num2 += max(b[i]-x,0LL); 35 if(A > B) res += num2 * B; 36 else 37 { 38 res += min(num1,num2) * A; 39 res += max((num2-num1) * B,0LL); 40 } 41 42 Ans = min(Ans,res); 43 return res; 44 } 45 46 int main() 47 { 48 A=get(); B=get(); C=get(); 49 n=get(); m=get(); 50 for(int i=1;i<=n;i++) t[i]=get(), MaxN=max(MaxN,t[i]); 51 for(int i=1;i<=m;i++) b[i]=get(); 52 53 if(C >= 1e16) 54 { 55 for(int i=1;i<=n;i++) MaxN=min(MaxN,t[i]); 56 printf("%lld",Judge(MaxN)); 57 } 58 59 s64 a,b,pass; 60 s64 l = 0, r = MaxN+1; 61 while(l < r-2) 62 { 63 pass = (r-l)/3; 64 a = l+pass; b = r-pass; 65 if(Judge(a) < Judge(b)) r = b; 66 else l = a; 67 } 68 69 printf("%lld",Ans); 70 71 } 72
View Code

【BZOJ4868】期末考試 [三分][貪心]