Baidu star qualifying round J-Question: Baidu's new building

Source: Internet
Author: User

Question: Chinese question, not explained

Idea: Simply solve the equation. Set the elevator to rise a at a time, drop B at a time, and press the button n times in total, and press the push button X times, then, the elevator is located at a * X-B * (N-x). Just find the minimum positive value that satisfies this formula. There are a total of 2000 elevators. You can find the minimum value for each elevator.

AC code:

# Include <iostream> # include <cstdio> # include <string. h> using namespace STD; struct house {int Up, down;} HH [2012]; int fun (int x, int y, int N) {int num = (y * N)/(x + y); int mod = (y * n) % (x + y); If (mod = 0) {return X + Y;} else {int ans = (Num + 1) * (x + y)-(y * n); Return ans ;}} int main () {int n, m; while (~ Scanf ("% d", & N, & M) {int X; int ans = 100000000; For (INT I = 0; I <m; ++ I) {scanf ("% d", & HH [I]. up, & HH [I]. down); X = fun (HH [I]. up, HH [I]. down, n); If (x <ans) ans = x;} printf ("% d \ n", ANS);} return 0 ;}

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.