1023: Black stores of hookay, 1023 black stores

Source: Internet
Author: User

1023: Black stores of hookay, 1023 black stores
Description

Today, James went to a picturesque place to relax, but after drinking his own drinks, James was thirsty. Seeing a small store not far away, he ran to buy a drink.

JAMES: "I want to buy a drink !"

Shopkeeper: "We have three drinks, one bottle of mineral water of 1.5 yuan, one bottle of cola of 2 yuan, and one bottle of orange juice of 3.5 yuan ."

JAMES: "Okay. Give me a bottle of mineral water ."

Then he handed out a N yuan bill and handed it to the shopkeeper.

Shopkeeper: "I forgot to remind you that we don't have the habit of looking for money from our guests. We accept the tip for a lot of money ."

JAMES: "..."

James looked around and decided to buy this store. But I think it would be better for me to buy more drinks than to give him money as a tip. I would like to drink it sooner or later, but I should try to make him a tip as little as possible.

Now James hopes that you can help him calculate the minimum tip he will give to the shopkeeper.

Input Format

The first line of the input data is an integer T (1 <= T <= 100), representing the number of test data. Then there is T-row test data. Each test data contains only one positive integer N (1 <= N <= 10000). N represents the nominal value of the money in James's hand, which is divided into units.
Note: There are only three drinks described in the store.

Output

For each group of test data, please export the minimum amount of money James will waste to the shopkeeper as a tip, divided into units.

Sample Input

2
900
250

Sample output

0
50

The algorithm that was originally thought of was incorrect.

 1 #include <stdio.h> 2 int main(void) 3 { 4     int time; 5     int money; 6     int remain; 7      8     scanf("%d",&time); 9     while(time--)10     {11         scanf("%d",&money);12         remain=money%350;13     14         remain=remain%200;15         16         remain=remain%150;17         if(money<150)18             money=remain;    19         printf("%d\n",remain);20     }21     return 0;22 }

Later, I found that this algorithm is not correct, for example, 450 = 3*150. In my algorithm, I first subtract 350, leaving 100.

The following is the official code for reference.

#include<stdio.h>int main(){        int t,n;        scanf("%d",&t);        while(t--)        {                scanf("%d",&n);                if(n<150)                        printf("%d\n",n);                else if(n<=200||n>=300)                        printf("%d\n",n%50);                else                        printf("%d\n",n-200);        }        return 0;}

The following code can be easily understood from CSDN. It is equivalent to a polynomial of 150 * x + 200 * y + 350 * z. x, y, and z try to get the value closest to money from the maximum value to 0.

Link: http://blog.csdn.net/u011470356/article/details/9412157

 1 <span style="font-size:18px;">#include <iostream> 2 using namespace std; 3 int main() 4 { 5     int n; 6     cin>>n; 7     int m,i,j,k; 8  9     for(m=0;m<n;m++)10     {11         int max=0;12         int s;13         cin>>s;14         for(i=s/350;i>=0;i--)15         {16             for(j=(s-i*350)/200;j>=0;j--)17             {18                 for(k=(s-i*350-j*200)/150;k>=0;k--)19                 {20                     int p=i*350+j*200+k*150;21                     if(p>max)22                     max=p;23                 }24             }25 26         }27         cout<<s-max<<endl;28 29 30     }31     return 0;32 }</span>

 


Hookay's black store

There are a lot of vendors. Be careful
 
Gitzo? Hookay's black store

There are a lot of vendors. Be careful

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.