C语言问题,提供思路就行(当然有伪代码甚至完整代码就更好了)In every summer there are students graduating from school.A lot of graduating students would like to host their parties to say good-bye to their classmates and frie

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/28 07:34:36

C语言问题,提供思路就行(当然有伪代码甚至完整代码就更好了)In every summer there are students graduating from school.A lot of graduating students would like to host their parties to say good-bye to their classmates and frie
C语言问题,提供思路就行(当然有伪代码甚至完整代码就更好了)
In every summer there are students graduating from school.A lot of graduating students would like to host their parties to say good-bye to their classmates and friends.This kind of activity is called "bg" on our BBS.
Attending different parties will give you different feelings.You may assign each party a degree of happiness which is a non-negative integer that shows how you feel about attending to that party.
Now you are given a list of parties containing the length of each party and the time on which the host will be leaving school.It would be nice to schedule the parties so that you can obtain maximum of happiness.Since there could be as many as 30 parties on the list,you'll need the computer to help you.
Input Specification:
Your program must read test cases from standard input.
The input file consists of several test cases.Each case starts with an integer N ( 30),then followed by N lines each in the format
h l t
where h is the degree of happiness,l is the length of the party (in hours),and t is the hours after which the host will be leaving the school.It is guaranteed that l is no greater than t,since if the host will leave at the end of the t-th hour,the party will have to end by that time.
The input is finished by a negative N.
Output Specification:
For each test case,your program must output to standard output.First print in one line the maximum degree of happiness.In the next line print a possible schedule in the format:
i1 i2 ...ik
where i1 i2 ...ik are the index numbers of the parties (start counting from 1).
Note:once you select a party,you must join the party from the beginning to the end.The time taken to run from one party to another can be omitted.
In case that the solutions are not unique,output any one of them will do.
Sample Input:
4
5 1 1
10 2 3
6 1 2
3 1 1
-1
Sample Output:
16
3 2

C语言问题,提供思路就行(当然有伪代码甚至完整代码就更好了)In every summer there are students graduating from school.A lot of graduating students would like to host their parties to say good-bye to their classmates and frie
首先,好像数据的格式是 权重(happiness)开始时间、结束时间.题中所说的聚会主办者离开学校的时间好像跟本题无关.按这种理解,测试数据能通过,如果按题目说的权重、持续时间、可能的结束时间的话,测试数据产生的结果就不是16 3 2
程序编制的思路大致如下:
先对聚会做个排序,按开始时间从早到晚排序,如果时间相同,权重大的往前排.然后从第一个聚会开始找出所有可能的组合并记录.可能的组合指的是时间不冲突,也就是对于一个组合,其任意两个聚会,排在前面的聚会的结束时间要不晚于排在后面的那个聚会的开始时间,然后计算总权重,如果比现有的总权重高,就替换.
P[]是保存聚会数组
p[]排序
main(){
structure { int h int l int t int ID} as party ID是聚会的识别号,按读入数据的先后顺序依次编号.
定义堆栈结构,包含两个成员,一个是聚会,一个是一个整数,这个整数用位置来代替,用 push pop来进行进出栈操作.
定义当前解决方案结构,我们用数组S来表示,同时用v来表示这个解决方案的总权重
for(i=0;i

C语言问题,提供思路就行(当然有伪代码甚至完整代码就更好了)In every summer there are students graduating from school.A lot of graduating students would like to host their parties to say good-bye to their classmates and frie C语言闰年伪代码怎么表示 C语言中伪代码是什么意思 C语言do while这里看不懂,这两个伪代码有什么区别吗 求fleury算法的伪代码 或C语言实现 高中数学导数求导的流程图(算法),用C语言写也行,VB也行,伪代码也行 有3个数abc,要求按大小顺序输出 用N-S图和伪代码表示算法-C语言作业 有3个数abc,要求按大小顺序输出 用N-S图和伪代码表示算法. 学C语言算法与数据结构买什么书好,不是伪代码的 C语言伪代码中的那个右箭头什么意思啊,半天没看懂, 用C语言编写程序,判断一个字符序列中(与)、[与]、{与}是否配对且互不相交给思路就行,不用代码 求m个数中最小的k个数,用C语言伪代码怎么编写啊?要完整的代码呀, 有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和.当然,依旧是使用C语言以下是我的代码,我想知道最后需不需要化简呢?最后结果是不是最简的?我的代码什么地方有问题啊?还 C语言素数环问题的思路 C语言解不等式的一个编程问题,只要代码 求C语言代码:分支限界法解背包问题 请使用伪代码编写算法:要求分别用循环结构和递归结构求解n!.= 1 当n=0 =n*(n--1)!当n>0是伪代码不是C语言 下面()可描述8皇后问题算法(多选)a自然语言b流程图c机器语言d伪代码 用C语言编写一个程序,统计一个字符串中 各种 小写字母(26个小写字母)出现次数,就如同题目中所说的,当然有程序和思路解析的更好,小弟在此谢过了!