La 4725 (Binary) Airport

Source: Internet
Author: User
Tags define local

Question:

There are two runways, W and E. Each runway is numbered from 0 at each time, and each time there are WI and EI planes arriving at these two runways. In addition, only one plane on the runway can take off at each time. Ask how to minimize the maximum number of aircraft. (The number is calculated at each time point before the plane departs)

Ideas:

It is also the smallest problem of the maximum value. Binary can be used, but I didn't think of binary.

Reference to someone else's code: http://blog.csdn.net/u011345136/article/details/17793415

The departure decision is as follows:

If one runway is empty and the other runway has an airplane, it must be the runway with an airplane.

If both runways have planes, add one record of the number of departures.

Assume that the maximum number is K. If the two runways come out more than K, the maximum number is larger than K.

 

1 // # define local 2 # include <iostream> 3 # include <cstdio> 4 # include <cstring> 5 using namespace STD; 6 7 const int maxn = 5000 + 10; 8 const int INF = 150000; 9 int A [maxn], B [maxn], n; 10 11 bool check (int K) 12 {13 int A = 0, B = 0, AA, BB, sum = 0; // a B is the number of planes on two runways respectively. 14 for (INT I = 0; I <n; ++ I) 15 {16 A + = A [I]; 17 B + = B [I]; 18 AA = max (a-k, 0 ); 19 BB = max (B-K, 0); 20 if (AA + BB> sum) return false; 21 if (a = 0 & B) -- B; 22 else if (B = 0 & A) -- A; 23 else if (A & B & A + B> sum) ++ sum; // a + B <= sum indicates that neither runway has a plane 24} 25 return true; 26} 27 28 int main (void) 29 {30 # ifdef local31 freopen ("4725in.txt", "r", stdin); 32 # endif33 34 int t; 35 scanf ("% d", & T ); 36 while (t --) 37 {38 scanf ("% d", & N); 39 for (INT I = 0; I <n; ++ I) 40 scanf ("% d", & A [I], & B [I]); 41 42 int L = 0, r = inf; 43 44 int ans; 45 while (L <= r) 46 {47 int mid = (L + r)> 1; 48 if (check (MID) 49 {50 ans = mid; 51 r = mid-1; 52} 53 else l = Mid + 1; 54} 55 printf ("% d \ n", ans-1); 56 57} 58 59 return 0; 60}
Code Jun

 

La 4725 (Binary) Airport

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.