杭州电子科技大学程序设计竞赛(2016’12)- 网络同步赛 1003

洗衣服

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
学校的洗衣机有4种模式:1、单脱水;2、快速洗;3、标准洗;4、大物洗。分别对应的价格是1、2、3、4元。
其中——
单脱水最多脱水3件衣服(无清洗功能);
快速洗最多3件(脱水+清洗);
标准洗最多6件(脱水+清洗);
大物洗最多洗10件(脱水+清洗)。
温馨提醒:以上可以看出,洗衣服中包含脱水功能。
现在XZ累积了n件衣服要处理,其中有m(m<=n)件只需要脱水的,另外n-m件必须清洗。问最少需要几元能把所有衣服处理完?
Input
输入数据第一行是一个正整数T(<=30),表示测试数据组数。
接下来T行,每行两个正整数 n m (n,m <=1e6)。
Output
对于每组数据,输出一行答案。
Sample Input
3
5 2
20 15
100 3
Sample Output
3
8
40
解法:不是我写的,听学弟的做法是拼凑3,6,10
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    int n,m;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        int x=n-m,y=m,ans=0;
        ans+=x/10*4;
        x%=10;
        if(x==0)
        {
            ans+=(y+2)/3;
        }
        else
        {
            if(x+y<=3)
            {
                ans+=2;
            }
            else if(x+y<=6)
            {
                ans+=3;
            }
            else if(x+y<=10)
            {
                ans+=4;
            }
            else
            {
                ans+=4;
                ans+=(x+y-10+2)/3;
            }
        }
        printf("%d
",ans);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/yinghualuowu/p/6217913.html