码迷,mamicode.com
首页 > 其他好文 > 详细

C. Tavas and Karafs 二分查找+贪心

时间:2015-04-15 21:22:40      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:

                                    C. Tavas and Karafs

 

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <string>
 7 #include <vector>
 8 #include <set>
 9 #include <map>
10 #include <stack>
11 #include <queue>
12 #include <sstream>
13 #include <iomanip>
14 using namespace std;
15 typedef long long LL;
16 const int INF = 0x4fffffff;
17 const double EXP = 1e-5;
18 const int MS = 40005;
19 const int SIZE = 100005;
20 
21 int main()
22 {
23       LL A,B,n;
24       LL L,T,M;
25       cin>>A>>B>>n;
26       for(LL i=0;i<n;i++)
27       {
28             cin>>L>>T>>M;
29             LL minv=(L-1)*B+A;
30             if(T<minv)
31             {
32                   cout<<"-1"<<endl;
33                   continue;
34             }
35             LL R=(T-minv)/B;
36 
37            int tl=L;
38            int tr=L+R+1;
39            while((tr-tl)>1)        //二分查找用[a,b)使用方便,又不易出错。
40            {
41                  LL mid=(tr+tl)>>1;
42                  LL sum=(mid-L+1)*A+(mid+L-2)*(mid-L+1)/2*B;
43                  LL maxv=(mid-1)*B+A;
44 
45                  LL time=sum/M;
46                  if(sum%M!=0)
47                         time++;
48                  time=max(time,maxv);
49                  if(time<=T)
50                         tl=mid;
51                  else
52                         tr=mid;
53            }
54             cout<<tl<<endl;
55       }
56       return 0;
57 }

 

C. Tavas and Karafs 二分查找+贪心

标签:

原文地址:http://www.cnblogs.com/767355675hutaishi/p/4430137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!