JOJ 2360: Trading Transaction

Status In/Out TIME Limit MEMORY Limit Submit Times Solved Users JUDGE TYPE
stdin/stdout 5s 16384K 738 55 Standard

In Chinese currency system, the bills come in 100, 50, 20, 10, 5, 2 and 1 denominations. When you buy something, the money you give to the salesman is a combination of these denominations. If the money you have paid is more than actual price, the salesman will return change with the least number of bills. For example, if you pay one 100-bill and one 50-bill to buy goods worth 123. The salesman should return you three bills: one 20-bill, one 5-bill and one 2-bill. If the salesman has no 5-bill, he would give you five bills: one 20, three 2 and one 1. If the salesman doesn’t have enough petty cash, he can apply any number of 1-bills. If the money you paid is less than the goods’ price, the salesman will refuse this business.

Input

For each test case, the first line contains the price of the goods, the second line contains the money you pay, and the third line contains the money that the salesman has. We present the money with 7 integers, which mean the numbers of 100-bill, 50-bill, 20-bill, 10-bill, 5-bill, 2-bill and 1-bill respectively.

Output

For each case, you should output the type of this transaction, which can be “Refuse”, “Accept”, and “Apply”, then output seven integers denoting the change. If the type is “Refuse”, you should just output seven 0s.

Sample Input

123
1 1 0 0 0 0 0
100 100 100 100 0 100 100
1
0 0 0 0 1 0 0 
0 0 0 0 0 0 1
10
0 0 0 0 0 0 3
1 1 1 1 1 1 1

Sample Output

Accept
0 0 1 0 0 3 1
Apply
0 0 0 0 0 0 4
Refuse
0 0 0 0 0 0 0

 

Problem Source: 1st Jilin Province Contest, skywind

#include<stdio.h>
#include<string.h>
#define Inf 2147483644
struct t
{
int num;
int val;
}a[7],b[7];
int sum,c[7],minc,mdd[7],min,minc2;
bool flag;
void dfs(int money,int counts,int mark)
{
    if(mark==7)
    {
         if(money==0&&counts<minc)
         {        
                minc = counts;
                for( int j = 0 ;j < 7 ; ++j) c[j] = mdd[j];
                flag = true;
         }
         else
         if(!flag&&money!=0&&money<min&&counts<minc2)
         {
             minc2=counts;
             min=money;
             for( int j = 0 ;j < 7 ; ++j) c[j] = mdd[j];
         }                
         return ;
    } 
    if(counts+money/b[mark].val> minc)  return ;
    if(money<b[mark].val)
        dfs(money,counts,mark + 1);
    else
    {
        int t=money/b[mark].val;
        int nums=(t< b[mark].num?t:b[mark].num);
        for(int i=nums;i>=0;--i)
        {
            mdd[mark]=i;
            dfs(money-b[mark].val*i,counts+i,mark +1);
            mdd[mark] = 0;
        }
    }
}
int main()
{
int i,money;
a[0].val=b[0].val=100;
a[1].val=b[1].val=50;
a[2].val=b[2].val=20;
a[3].val=b[3].val=10;
a[4].val=b[4].val=5;
a[5].val=b[5].val=2;
a[6].val=b[6].val=1;
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d",&money)!=EOF)
{
        memset(c,0,sizeof(c));
sum=0;
for(i=0;i<7;i++)
{
    scanf("%d",&a[i].num);
            sum+=a[i].val*a[i].num;
}
for(i=0;i<7;i++)
{
    scanf("%d",&b[i].num);
b[i].num+=a[i].num;//钱时全部要先给售货员的
}
if(sum<money)
        {
            printf("Refuse/n");
            printf("0 0 0 0 0 0 0/n");
        }
        else
        {
            minc = Inf;
            min=Inf;
            minc2=Inf;
            flag = false;
            dfs(sum-money,0,0);
            if(flag)
            {
                printf("Accept/n");
    for(i=0;i<6;i++)
          printf("%d ",c[i]);
    printf("%d/n",c[i]);
            }
            else
            {
              printf("Apply/n");
  for(i=0;i<6;i++)
       printf("%d ",c[i]);
  printf("%d/n",c[i]+min);
}
         }
    }
return 0;
}

你可能感兴趣的:(c,struct,360,each,output,Numbers)