2360: Trading Transaction

 2360: Trading Transaction


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
5s16384K82167Standard

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

 


This problem is used for contest: 63  145 

 

 

#include<iostream>
#include<string.h>
using namespace std;
const int inf=123456789;
int coin[7]={100,50,20,10,5,2,1};
int n,a[7],b[7];
int re[7],md[7];
int minc;
bool flag;
void out()
{
    int i;
    for( i = 0 ; i < 6 ;i++) cout << re[i] << " ";
        cout << re[6] << endl;
}
void dfs(int money,int count, int mark)//money 剩余的钱  ,count  钱的张数 ,mark  节点
{
 if(mark==7)
 {
  if(money==0&&count<minc)
  {
   minc=count;
   for(int i=0;i<7;i++)
    re[i]=md[i];
   flag=true;
  }
  return ;
 }
 if(count + money/coin[mark] > minc) return ;
 if(money<coin[mark])
  dfs(money,count,mark+1);
 else
 {
  int t=money/coin[mark];
  int nums=t<b[mark]?t:b[mark];
  int i;
  for(i=nums;i>=0;i--)
  {
   md[mark]=i;
   dfs(money-coin[mark]*i,count+i,mark+1);
  // md[mark]=0;
  }
 }
}

 

int main()
{
 int i;
 while(scanf("%d",&n)==1)
 {
  for(i=0;i<7;i++)
  {
   scanf("%d",&a[i]);
  }
  for(i=0;i<7;i++)
  {
   scanf("%d",&b[i]);
   b[i]+=a[i];
  }
  int sum=0;
  for(i=0;i<7;i++)
  {
   sum+=a[i]*coin[i];
  }
  if(sum<n)
  {
   printf("Refuse/n0 0 0 0 0 0 0/n");
   continue;
  }
  flag=false ;
  minc=inf;
  dfs(sum-n,0,0);
  if(flag)
  {
   printf("Accept/n");
   out();
  }
  else
  {
   //memset(re,0,sizeof(re));
   //memset(md,0,sizeof(md));
   b[6]=inf;
   dfs(sum-n,0,0);
   printf("Apply/n");
   out();
  }
 }
 return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值