POJ 3863 Business Center

Source: Internet
Author: User
Tags integer numbers

Business Centertime limit:1000msmemory limit:65536kbthis problem'll be judged onPKU. Original id:3863
64-bit integer IO format: %lld Java class name: Main International Cyber Police Corporation (ICPC) had built a new Mega-tall business center to host their headquarters and to Le ASE some space for extra profit. It had so many floors, which is it's impractical to having a separate button in each of their m elevator cars for each individual Floor. Instead, each elevator car has just and a buttons. One button in i-th elevator car makes it move up UI floors, and the other makes it move down di floors. The business center was so high, which we can ignore its height for this problem (you'll never reach the top floor), but Y OU cannot go below the ground floor. All floors is numbered by an integer numbers starting from zero and zero being the ground floor.
You start at the ground floor of the business center. You has to choose one elevator car out of M to ride on. You cannot switch elevators cars after that. What's the lowest floor above the ground floor can I get to after you press elevator car buttons exactly n times?InputThe first line of the input file contains double integer numbers n and m (1 <= N <= 1, 1 <= m <= 2 000)- The number of button presses and the number of elevator cars to choose from. The following m lines describe elevator cars. Each line contains the numbers UI and Di (1 <= UI, Di <= 1 000).OutputWrite to the output file a single positive integer number-the number of the lowest floor above ground floor so can be Reached by one of the M elevators after pressing its buttons exactly n times.Sample Input
10 315 1215) 47 12
Sample Output
13
SourceNortheastern Europe 2009 Problem Solving: Directly engage in the chant. Seems to require at least the last time
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 LL N,m,u,d,ret;5 voidCheck () {6LL tmp = (n*d+u+d)/(u+d);7ret = min (ret, (u+d) *tmp-n*d);8 }9 intMain () {TenIos::sync_with_stdio (false); OneCin>>n>>m; ARET =Int_max; -      while(m--) { -Cin>>u>>D; the check (); -     } -cout<<ret<<Endl; -     return 0; +}
View Code

POJ 3863 Business Center

Related Article

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.