poj 1010 STAMPS

STAMPS

Time Limit: 1000MS

Memory Limit: 10000K

Total Submissions: 14445

Accepted: 4054

Description

Have you done any Philately lately? 

You have been hired by the Ruritanian Postal Service (RPS) to design their newpostage software. The software allocates stamps to customers based on customerneeds and the denominations that are currently in stock. 

Ruritania is filled with people who correspond with stamp collectors. As aservice to these people, the RPS asks that all stamp allocations have themaximum number of different types of stamps in it. In fact, the RPS has beenknown to issue several stamps of the same denomination in order to pleasecustomers (these count as different types, even though they are the samedenomination). The maximum number of different types of stamps issued at anytime 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 integersequences, consisting of two lines, alternating until end-of-file. The firstsequence are the available values of stamps, while the second sequence is aseries 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 filescontain only integers.

Output

For each customer, you should print the "best"combination that is exactly equal to the customer's needs, with a maximum offour stamps. If no such combination exists, print "none". 
The "best" combination is defined as the maximum number of differentstamp types. In case of a tie, the combination with the fewest total stamps isbest. If still tied, the set with the highest single-value stamp is best. Ifthere 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 andthe actual stamps. In case of no legal allocation, the line should look like itdoes 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 inthe example).Don't print extra blank at the end of each line. 

Sample Input

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

Sample Output

7 (3): 1 1 2 3 
4 (2): 1 3 
6 ---- none
2 (2): 1 1
3 (2): tie

Source

PacificNorthwest 1998

 

STAMPS

Time Limit: 1000MS

Memory Limit: 10000K

Total Submissions: 14445

Accepted: 4054

Description
你最近有收集邮票么?
你被Ruritanian Postal Service(RPS)雇佣设计新的计算邮费的软件软件根据顾客需求和现存的面额来分配邮票
Ruritania有很多邮票收藏家,为了向这些人提供更好的服务,RPS要求邮票的分配能拥有最多的不同类型的邮票。事实上,RPS已知现发行的几种邮票有着相同的面额(这些在计算时当做不同的类型,虽然他们有相同的额面额)。无论何时邮票的最多发行类型为25。

为了省钱,RPS希望发行尽可能少的重复邮票(给出他们想要发行的不同的类型的约束条件)。进一步而言,RPS不会同时发售超过4枚邮票。

Input
对于你程序的输入酱包括几对正整数序列,包括两行交替,直道文件末尾。第一个序列是邮票的价值,第二个序列是一系列的顾客的要求。比如:
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 3个顾客

注解:后面的注释不是输入数据,输入数据只有数字

Output
对于每一个客户,你应给输出“最好”的组合能够确实满足顾客的需求,对于最大只能有四枚邮票。如果没有这种组合,则输出“none”.

“最好“的组合定义为最大数量的不同邮票种类。在得分相同的情况下,组合中需要最少邮票的优于其他组合。如果仍然得分相同,组合中拥有单个邮票价值最高的最好。如果仍然得分相同,则输出“tie”。
对于示例输入,对应输出如下:
7 (3): 1 1 2 3 
4 (2): 1 3 
6 ---- none 
2 (2): 1 1 
3 (2): tie 

这里表示,你应该输出顾客的要求,卖出的邮票种类,和实际销售的邮票。如果没有合理的分配,输出应该如同示例一样,在一个空格后有4个连字符。在得分相同的情况下,仍然输出类型的数量,但是不输出分配结果(如同示例一样)。在每一行的结尾,不要输出其他的空白。

Sample Input

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

Sample Output

7 (3): 1 1 2 3 
4 (2): 1 3 
6 ---- none
2 (2): 1 1
3 (2): tie

Source

PacificNorthwest 1998

 

 

由于题目属于比较难理解类型的….所以还是得重新描述一下问题,重述问题来自于:http://blog.csdn.net/cugbliang/article/details/2742242为了方便复制粘贴一下owo:

给出n种邮票,每种邮票有自己的面值(面值可能重复)

       指定m种“总面值”,对每种“总面值”,求解满足如下条件的组合以达到该“总面值”

(1)       所用邮票在n种中可以重复选取

(2)       所用邮票张数〈=4

(3)       尽量多的使用那个不同种类的邮票 Max (Stamp Types)

(4)       若有多种方案满足(3),则选取张数最小的一种方案 Min (Stamp Num)

(5)       若有多种方案满足(3)(4),则选取“最大面额”最高的一种方案。 Max(Heightest Value)

(6)       若有多种方案满足(3)(4)(5) 则输出 “tie”


这道题最恶心的数据范围没说清楚,等等各种东西都说的看的迷迷糊糊........按照前人的经验,邮票数量是可能大于25的,于是索性设置数组大小111了。而后的输出是应该俺顺序输出的,这俩弄死我好几回.......所以一开始就做了个计数排序,因为反正就111个数,计数排序妥妥无鸭梨。而后就是简单枚举了....从前往后考虑,先处理,张数最小,然后处理面额最大,最后处理tie的问题。tie记得每次更新都要更新他.....

#include<iostream>
#include<cmath>
#include<algorithm>
#include <stdio.h>
#include <string.h>

#define MAX_Count 111

int main(void)
{
	int k = 0;
	int count_type[MAX_Count]={0};
    int stamp_type[MAX_Count];
    int out[4];
    int stamp_quest, stamp_type_num;
    int st;
    int Tie_sum = 1;

//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	while(scanf("%d", &st) != EOF)
	{
        int max_num = -1;
	    for (int i = 0;i < MAX_Count;i ++) count_type[i] = 0;
		if (st > max_num)
            max_num = st;
		count_type[st]++;//for first input

		while(scanf("%d", &st) && st)
		{
		    if (st > max_num)
                max_num = st;
			if (count_type[st] < 5)	//for other
                count_type[st] ++;
		}
		for (int i = 0;i <= max_num;i ++){
            while(count_type[i]--){
                stamp_type[k++] = i;
            }
		}
		stamp_type[k++] = 0;
		stamp_type_num = k;k = 0;
//		for (int i = 0;i < stamp_type_num;i ++){
//            printf("%d ", stamp_type[i]);
//		}
//		printf("\n");

		while(scanf("%d", &stamp_quest) && stamp_quest)
		{
			int type_sum = -1;
			int num_sum = -1;
			int max_sum = -1;
			for (int i = 0;i < stamp_type_num;i ++)
				for (int j = i;j < stamp_type_num;j ++)
					for (int k = j;k < stamp_type_num;k ++)
						for (int p = k;p < stamp_type_num;p ++)
						{
							if (stamp_type[i] + stamp_type[j] + stamp_type[k] + stamp_type[p] != stamp_quest) continue;
//                            printf("%d %d %d %d\n", stamp_type[i], stamp_type[j], stamp_type[k], stamp_type[p]);
							int qus_one = 0;
							int qus_two = 0;
							int max_stamp = 0;

                            if (stamp_type[i]){qus_one++; qus_two++; if (stamp_type[i] > max_stamp) max_stamp = stamp_type[i];}
							if (stamp_type[j]){qus_one++; if(j > i) qus_two++; if (stamp_type[j] > max_stamp) max_stamp = stamp_type[j];}
							if (stamp_type[k]){qus_one++; if(k > j) qus_two++; if (stamp_type[k] > max_stamp) max_stamp = stamp_type[k];}
							if (stamp_type[p]){qus_one++; if(p > k) qus_two++; if (stamp_type[p] > max_stamp) max_stamp = stamp_type[p];}

							if (type_sum < qus_two)
							{
								type_sum = qus_two;
								num_sum = qus_one;
								max_sum = max_stamp;
								out[0] = i;out[1] = j; out[2] = k; out[3] = p;
								Tie_sum = 0;
								continue;
							}else if (type_sum > qus_two) continue;

							if (num_sum > qus_one)
							{
								type_sum =qus_two;
								num_sum = qus_one;
								max_sum = max_stamp;
								out[0] = i;out[1] = j; out[2] = k; out[3] = p;
								Tie_sum = 0;
								continue;
							}else if (num_sum < qus_one) continue;

							if (max_sum < max_stamp)
							{
								type_sum = qus_two;
								num_sum = qus_one;
								max_sum = max_stamp;
								out[0] = i; out[1] = j; out[2] = k; out[3] = p;
								Tie_sum = 0;
								continue;
							}else if (max_sum > max_stamp) continue;
							Tie_sum = 1;
						}
			if (type_sum == -1){
				printf("%d ---- none\n", stamp_quest);
                continue;
			}
			printf("%d (%d):", stamp_quest, type_sum);
			if (Tie_sum){
				printf(" tie\n");
				continue;
			}
			for (int i = 0;i < 4;i ++)
				if (stamp_type[out[i]] > 0) printf(" %d", stamp_type[out[i]]);
			printf("\n");
		}

	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值