Labeling Balls(拓扑)】的更多相关文章

Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10161   Accepted: 2810 Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 toN in such a way that: No two balls share…
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13201 Accepted: 3811 Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 to N in such a way that: No two balls share the…
题目:http://poj.org/problem?id=3687题意:n个重量为1~n的球,给定一些编号间的重量比较关系,现在给每个球编号,在符合条件的前提下使得编号小的球重量小.(先保证1号球最轻,其次2号……) 然后,按照重量1~n的输出位置 要倒序建图,优先选择编号大的 给编号大的   拓扑排序,注意根据题的要求,要先保证1号球最轻,如果我们由轻的向重的连边,然后我们依次有小到大每次把重量分给一个入度为0的点,那么在拓扑时我们面对多个入度为0的点,我们不知道该把最轻的分给谁才能以最快的速…
题目大意:原题链接 给出N个未编号的质量各不相同的球,以及它们质量轻重的大小关系,给它们从1-N贴标签编号,无重复.问是否存在可行的编号方法,不存在输出-1, 如果存在则输出唯一一种方案,此方案是使得编号小的球的重量尽量轻,先是编号为1的重量要最轻,其次比编号2,以此类推...... 思路:当解有多组时,编号小的质量尽量小.所以就采用逆拓扑排序(正向的贪心不能完全保证序号小的节点尽量排在前面.仔细思考~~~~~), 按编号从大到小,找质量最大的.这样,小标签就都留给了质量小的.比如4-->1,3…
http://poj.org/problem?id=3687 看题意看了半天没看懂怎么回事,看完Discuss彻底凌乱了..后来看了题解才懂,就是逆向建图+拓扑排序,建图时要判重边. #include<stdio.h> #include<string.h> ][]; ],ans[]; int topo() { int i,j; ; i --) { ; j --) { if (!in[j]) { ans[j] = i; --in[j]; break; } } ) ; ; k <…
1 问题描述 给出一些球,从1N编号,他们的重量都不相同,也用1N标记加以区分(这里真心恶毒啊,估计很多WA都是因为这里),然后给出一些约束条件,< a , b >要求编号为 a 的球必须比 b 轻,现在要求按编号升序输出每个球的重量,如果有多种解,输出字典序最小的那个. 例如: input: 1 5 4 5 1 4 2 1 3 2 3 output: 2 4 5 3 1 package com.liuzhen.practice; import java.util.ArrayList; imp…
Labeling Balls DescriptionWindy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 to N in such a way that:No two balls share the same label.The labeling satisfies several constrains like "The ball labeled with…
Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12246   Accepted: 3508 Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 to N in such a way that: No two balls share…
Labeling Balls Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 20   Accepted Submission(s) : 10 Problem Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to…
Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16100   Accepted: 4726 Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 to N in such a way that: No two balls share…