JZOJ 3018. 【NOIP2012模拟10.9】电费结算
题目
分析
二分一下电量就okkk
代码
1 #include<iostream> 2 #define LL long long 3 using namespace std; 4 long long f[4][2]={{100,2},{10000,3},{1000000,5},{10000000000,7}}; 5 LL count1(int x) 6 { 7 if (x<=100) 8 return x*2; 9 else 10 if (x<=10000) 11 return 200+(x-100)*3; 12 else 13 if (x<=1000000) 14 return 200+29700+(x-10000)*5; 15 else 16 return 200+29700+990000*5+(x-1000000)*7; 17 } 18 int main () 19 { 20 LL a,b,c; 21 cin>>a>>b; 22 if (a<=200) 23 c=a/2; 24 else 25 if (a<=29900) 26 c=100+(a-200)/3; 27 else 28 if (a<=5249000) 29 c=10000+(a-29900)/5; 30 else 31 c=1000000+(a-4979900)/7; 32 LL l=0,r=c; 33 while (l<=r) 34 { 35 LL mid=(l+r)/2; 36 LL ll=count1(mid),rr=count1(c-mid); 37 if (ll-rr==b) 38 { 39 cout<<rr; 40 return 0; 41 } 42 else if (ll-rr<b) l=mid-1; 43 else if (ll-rr>b) r=mid+1; 44 } 45 }
为何要逼自己长大,去闯不该闯的荒唐