[POJ][1010]STAMPS
来源:互联网 发布:editplus软件汉化包 编辑:程序博客网 时间:2024/06/11 14:40
Description
Have you done any Philately lately?
You have been hired by the Ruritanian Postal Service (RPS) to design their new postage software. The software allocates stamps to customers based on customer needs and the denominations that are currently in stock.
Ruritania is filled with people who correspond with stamp collectors. As a service to these people, the RPS asks that all stamp allocations have the maximum number of different types of stamps in it. In fact, the RPS has been known to issue several stamps of the same denomination in order to please customers (these count as different types, even though they are the same denomination). The maximum number of different types of stamps issued at any time is twenty-five.
To save money, the RPS would like to issue as few duplicate stamps as possible (given the constraint that they want to issue as many different types). Further, the RPS won't sell more than four stamps at a time.
You have been hired by the Ruritanian Postal Service (RPS) to design their new postage software. The software allocates stamps to customers based on customer needs and the denominations that are currently in stock.
Ruritania is filled with people who correspond with stamp collectors. As a service to these people, the RPS asks that all stamp allocations have the maximum number of different types of stamps in it. In fact, the RPS has been known to issue several stamps of the same denomination in order to please customers (these count as different types, even though they are the same denomination). The maximum number of different types of stamps issued at any time is twenty-five.
To save money, the RPS would like to issue as few duplicate stamps as possible (given the constraint that they want to issue as many different types). Further, the RPS won't sell more than four stamps at a time.
Input
The input for your program will be pairs of positive integer sequences, consisting of two lines, alternating until end-of-file. The first sequence are the available values of stamps, while the second sequence is a series of customer requests. For example:
1 2 3 0 ; three different stamp types
7 4 0 ; two customers
1 1 0 ; a new set of stamps (two of the same type)
6 2 3 0 ; three customers
Note: the comments in this example are *not* part of the data file; data files contain only integers.
1 2 3 0 ; three different stamp types
7 4 0 ; two customers
1 1 0 ; a new set of stamps (two of the same type)
6 2 3 0 ; three customers
Note: the comments in this example are *not* part of the data file; data files contain only integers.
Output
For each customer, you should print the "best" combination that is exactly equal to the customer's needs, with a maximum of four stamps. If no such combination exists, print "none".
The "best" combination is defined as the maximum number of different stamp types. In case of a tie, the combination with the fewest total stamps is best. If still tied, the set with the highest single-value stamp is best. If there is still a tie, print "tie".
For the sample input file, the output should be:
7 (3): 1 1 2 3
4 (2): 1 3
6 ---- none
2 (2): 1 1
3 (2): tie
That is, you should print the customer request, the number of types sold and the actual stamps. In case of no legal allocation, the line should look like it does in the example, with four hyphens after a space. In the case of a tie, still print the number of types but do not print the allocation (again, as in the example).Don't print extra blank at the end of each line.
The "best" combination is defined as the maximum number of different stamp types. In case of a tie, the combination with the fewest total stamps is best. If still tied, the set with the highest single-value stamp is best. If there is still a tie, print "tie".
For the sample input file, the output should be:
7 (3): 1 1 2 3
4 (2): 1 3
6 ---- none
2 (2): 1 1
3 (2): tie
That is, you should print the customer request, the number of types sold and the actual stamps. In case of no legal allocation, the line should look like it does in the example, with four hyphens after a space. In the case of a tie, still print the number of types but do not print the allocation (again, as in the example).Don't print extra blank at the end of each line.
Sample Input
1 2 3 0; three different stamp types7 4 0; two customers1 1 0; a new set of stamps (two of the same type)6 2 3 0; three customers
Sample Output
7 (3): 1 1 2 3 4 (2): 1 3 6 ---- none2 (2): 1 13 (2): tie
这道题比较简单,因为最多只需要四种邮票,直接暴力搜索可以过,网上说题目的输入和要求不符,所以数组稍微开大了点
题目意思就是给你不同种类的邮票面值,面值可能相同,然后给你用户需要的总面值,你输出结果。
结果的格式是,用户需求总面值,括号里是最佳组合的邮票种类,没有的话输出---- none,如果总面值满足的情况下有多种组合,就输出种类多的,如果还有多种组合,就输出邮票张数少的,如果还有多种组合,输出最大面值大的,如果还有多种组合,输出tie。
如果检查到更优的情况,记得要把tie清空,这里的tie是最优解是否有重复。
下面是AC代码
#include<iostream>#include<algorithm>using namespace std;int main(){ int stamp[66]={0},v,solution[6]={0},kind=0;//v用作接收输入,solution里面第一个存种类,第二个存张数,后面四个寸邮票排序之后的下标,kind是输入邮票种类的计数器 while(cin>>v) { if(v!=0) stamp[++kind] = v; else { while(cin>>v && v!=0) { bool tie=false; solution[0]=0; solution[1]=0; cout<<v<<' '; sort(stamp+1,stamp+kind+1); for(int i=0;i<=kind;++i) for(int j=0;j<=kind;++j) for(int k=0;k<=kind;++k) for(int l=0;l<=kind;++l) { if(stamp[i]+stamp[j]+stamp[k]+stamp[l]>v) break; if(stamp[i]+stamp[j]+stamp[k]+stamp[l] == v) { int tempsolution[6]={0}; tempsolution[2]=i; tempsolution[3]=j; tempsolution[4]=k; tempsolution[5]=l; sort(tempsolution+2,tempsolution+6); if(tempsolution[2]!=0) { tempsolution[0]=tempsolution[1]=1; } for(int i=3;i<6;++i) if(tempsolution[i]!=0) { ++tempsolution[1]; if(tempsolution[i]!=tempsolution[i-1]) ++tempsolution[0]; } if(tempsolution[0]>solution[0]) { tie=false; for(int i=0;i<6;++i) solution[i]=tempsolution[i]; } else if(tempsolution[0]==solution[0]) { if(tempsolution[1]<solution[1]) { tie=false; for(int i=0;i<6;++i) solution[i]=tempsolution[i]; } else if(tempsolution[1]==solution[1]) { if(stamp[tempsolution[5]]>stamp[solution[5]]) { tie=false; for(int i=0;i<6;++i) solution[i]=tempsolution[i]; } else if(stamp[tempsolution[5]]==stamp[solution[5]]) { for(int i=0;i<6;++i) { if(tempsolution[i]!=solution[i]) { tie=true; if(tempsolution[0]==4) goto breakall; else for(int i=0;i<6;++i) solution[i]=tempsolution[i]; break; } } } } } } } breakall: if(solution[0]==0) cout<<"---- none"<<endl; else { cout<<'('<<solution[0]<<"): "; if(tie) cout<<"tie"<<endl; else for(int i=2;i<6;++i) { if(solution[i]!=0 && i!=5) cout<<stamp[solution[i]]<<' '; else if(i==5)cout<<stamp[solution[i]]<<endl; } } } kind=0; } } return 0;}
- POJ 1010 STAMPS
- poj 1010 STAMPS
- poj 1010 STAMPS
- POJ-1010-STAMPS
- [POJ][1010]STAMPS
- POJ 1010 STAMPS
- POJ - 1010 STAMPS
- POJ 1010: STAMPS
- POJ 1010 STAMPS(DFS)
- POJ 1010 STAMPS
- POJ 1010--STAMPS
- STAMPS POJ 1010
- poj 1010:STAMPS
- POJ 1010 STAMPS 笔记
- POJ 1010--STAMPS
- POJ 1010 解题报告 STAMPS
- POJ 1010 STAMPS 解题报告
- UESTC 408 STAMPS // poj 1010
- 简单的随机点名系统
- .sln文件和.suo文件的解释
- e.keyvalue的值的含义
- 显示器黑屏
- sealed关键字
- [POJ][1010]STAMPS
- 没有找到COMRes.dll因此这个应用程…
- SqlCe的安装
- 嵌入式
- 2009年07月02日
- 程序集
- KeyPress 和KeyDown 、KeyPress之…
- Head First设计模式-观察者模式
- C#中KeyData、KeyCode、KeyValue和…