Sdut the story of Little P--the magical dota__sizeof

Source: Internet
Author: User
Tags dota
the story of Little P--The magic DotA Time limit:1000ms Memory limit:65536k Topic DescriptionSmall p very like to play DotA, no day and night to play, the result of his dream is also inside the picture, one night little p just lie down to do a magical dream ... The undead Lich King pays his wages, the death knight gets an n dollar bill (remember, only one note), in order to prevent his frequent death in the fight, he decided to buy some props for himself, so he came to the Goblin shop before. Death Knight: "I want to buy props!" Goblin businessman: "We have three props here, blood bottles 150 pieces of one, magic medicine 200 pieces of one, invincible Potion 350 one." Death Knight: "OK, give me a blood bottle." He said he pulled out the N-dollar bill and handed it to the Goblin merchant. Goblin businessman: "I forgot to remind you that we do not find customers here the habit of money, much of the money we all when the tip of the pack, hey." Death Knight: "..." Death Knight thought, instead of the money as a tip to send him a little more than his own props, anyway, after all to buy, early bought to put at home or not, but to make it as little as possible to earn him tips. Now the Death Knight feels his IQ is not enough, so I hope little P help him calculate, at least he will give the Goblin merchants how much tips. But the IQ of small p is a famous "can't bear to look straight" Ah, smart extraordinary you so you can help him. inputThe first line of input data is an integer T (1<=t<=100) that represents the number of test data. Then the T-line tests the data, each test data contains only a positive integer n (1<=n<=10000), and n represents the face value of the money in the Death Knight's hand. Note: The Goblin store has only three props described in the question. OutputFor each set of test data, please output the Death Knight at least how much money to waste to the goblin businessman as a tip. Sample Input
2 
380 
200
Sample Output
 
0
Tips SourceXfl Sample Programs
#include <stdio.h>
int main ()
{
	int a,b;
	scanf ("%d", &a);
	while (a--)
	{
		scanf ("%d", &b);
		if (b>=1 && b<150)
            printf ("%d\n", b);
		else if (b>200 && b<300)
		    printf ("%d\n", b-200);
		else
		   printf ("%d\n", b%50);
	}
	return 0;
}

Dynamic programming
#include <stdio.h>
#include <stdlib.h>
int dp[10002];
int main ()
{
    int n, I, a[4]={150,200,350}, J, X;
    scanf ("%d", &n);
    while (n--)
    {
        scanf ("%d", &x);
        Memset (Dp,0,sizeof (DP));
        for (i=0;i<3;i++)
        {for
            (j=a[i];j<=x;j++)
            {
                if (Dp[j]<dp[j-a[i]]+a[i])
                   DP[J]=DP [J-a[i]]+a[i];
            }
        printf ("%d\n", X-dp[x]);
    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.