Greedy algorithm 1013

Source: Internet
Author: User

Main topic:

Give two number, profit and loss, the company in the annual statistics 8 times, each time the statistics 5 months, so there are overlapping parts, 8 times the result of statistics are deficit, seek profit

Problem Solving Ideas:

Since there is a deficit each time, so there is at least one D in 5 months, there are four cases, the number of months of profit *s-loss of the number of months *d for the request

Code:

#include <iostream>#include<algorithm>using namespacestd;intMain () {ints,d,sum;  while(cin>>s>>d) {if(4*s<d) Sum=Ten*s-2*D; Else if(3*s<2*d) Sum=8*s-4*D; Else if(2*s<3*d) Sum=6* (S-d); Else if(s<4*d) Sum=3*s-9*D; if(sum>0) cout<<sum<<Endl; Elsecout<<"deficit"<<Endl; }    return 0;}

Greedy algorithm 1013

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.