JOJ 2360: Trading Transaction
来源:互联网 发布:mac os x 10.12 beta 编辑:程序博客网 时间:2024/06/05 10:07
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
1231 1 0 0 0 0 0100 100 100 100 0 100 10010 0 0 0 1 0 0 0 0 0 0 0 0 1100 0 0 0 0 0 31 1 1 1 1 1 1
Sample Output
Accept0 0 1 0 0 3 1Apply0 0 0 0 0 0 4Refuse0 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;
}
- JOJ 2360: Trading Transaction
- Transaction
- Transaction
- Transaction
- transaction
- Transaction
- Transaction
- Transaction
- Transaction
- @Transaction
- transaction
- Transaction
- JOJ 2257
- joj 2319
- joj 2653
- JOJ 2687
- joj 2693
- joj 2443
- 使用PHP做Linux/Unix守护进程
- 29岁之前不要在乎的十件事
- 面试提问环节
- 删除桌面“恶意”图标
- 如何成为优秀软件设计师
- JOJ 2360: Trading Transaction
- 【转】注意 ExecuteNonQuery() 返回值 问题
- Java内存模型
- ubuntu nfs
- 如何交叉编译mkfs.jffs2等工具链mtd-utils
- UNIX环境高级编程学习之第十章信号-用信号实现父子进程同步
- ACE之基础篇
- 更改jar文件的打开方式
- TSC条码打印机