zoukankan      html  css  js  c++  java
  • hdu Hat's Tea

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1288

    去买茶,需要正好的钱才行,另外花的钱的个数最多  其实是一个简单的贪心问题,小的多取一点,多的少取一点。反着想,算出超出部分数量。

    代码:

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <math.h>
     4 #include <algorithm>
     5 #include <iostream>
     6 #include <ctype.h>
     7 #include <iomanip>
     8 #include <queue>
     9 #include <map>
    10 #include <stdlib.h>
    11 using namespace std;
    12 
    13 int main()
    14 {
    15     int i,j,k,t,m,x,y,z,n;
    16     while(cin>>m>>x>>y>>z && m+x+y+z){
    17         int sum=0;
    18         sum=x+y*5+z*10;
    19         n=m;
    20         if(sum<m)
    21             cout<<"Hat cannot buy tea."<<endl;
    22         else{
    23             m=sum-m;    //反着计算
    24             int z1=m/10;
    25             if(z1<z)
    26                 m=m-z1*10,z=z-z1;
    27             else
    28                 m=m-z*10,z=0;
    29             int y1=m/5;
    30             if(y1<y)
    31                 m=m-y1*5,y=y-y1;
    32             else
    33                 m=m-y*5,y=0;
    34             int x1=m;
    35             if(x1<x)
    36                 m=m-x1,x=x-x1;
    37             else
    38                 m=m-x,x=0;
    39             if(m!=0)
    40                 printf("Hat cannot buy tea.
    ");
    41             else
    42                 printf("%d YiJiao, %d WuJiao, and %d ShiJiao
    ",x,y,z);
    43         }
    44     }
    45 }
  • 相关阅读:
    测试面试题
    订单怎么测试?(主要测试订单的状态变化)
    还款功能怎么测试?
    登录功能怎么测试?
    apache配置详解与实践
    apache的安装
    linux系统优化(关闭SElinux、防火墙)
    linux网络配置
    linux的日志管理
    python的xlwt模块
  • 原文地址:https://www.cnblogs.com/wangmengmeng/p/4876954.html
Copyright © 2011-2022 走看看