POJ——T 3687 Labeling Balls】的更多相关文章

http://poj.org/problem?id=3687 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14842   Accepted: 4349 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…
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…
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 same label. The labeling satisfies several constrains like "The ball labeled with a is lighter than the on…
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…
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9641 Accepted: 2636 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…
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: 1000MS   Memory Limit: 65536K Total Submissions: 15792   Accepted: 4630 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: 1000MS   Memory Limit: 65536K Total Submissions: 14835   Accepted: 4346 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…
题目:http://poj.org/problem?id=3687题意:n个重量为1~n的球,给定一些编号间的重量比较关系,现在给每个球编号,在符合条件的前提下使得编号小的球重量小.(先保证1号球最轻,其次2号……) 然后,按照重量1~n的输出位置 要倒序建图,优先选择编号大的 给编号大的   拓扑排序,注意根据题的要求,要先保证1号球最轻,如果我们由轻的向重的连边,然后我们依次有小到大每次把重量分给一个入度为0的点,那么在拓扑时我们面对多个入度为0的点,我们不知道该把最轻的分给谁才能以最快的速…
题目链接: http://poj.org/problem?id=3687 要逆向建图,输入的时候要判重边,找入度为0的点的时候要从大到小循环,尽量让编号大的先入栈,输出的时候注意按编号的顺序输出重量,不是按重量大小输出编号.. 题目确实很简单,但是感觉很经典. #include <stdio.h> #include <string.h> #include <stack> using namespace std; ][], vis[]; ], weight[]; stac…
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 same label. The labeling satisfies several constrains like "The ball labeled with a is lighter…
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 same label. The labeling satisfies several constrains like "The ball labeled with a is lighter…
题意:给出n个人,m个轻重关系,求满足给出的轻重关系的并且满足编号小的尽量在前面的序列 因为输入的是a比b重,但是我们要找的是更轻的,所以需要逆向建图 逆向建图参看的这一篇http://blog.csdn.net/scf0920/article/details/28108243 然后用优先队列来实现的参看的这一篇 http://ycool.com/post/u9ahrwg#algo3 #include<iostream> #include<cstdio> #include<c…
(点击此处查看原题) 题意 此处有n盏灯,编号为1~n,每盏灯的亮度都是唯一的,且在1~n范围之间,现已知m对灯之间的关系:a b ,说明灯a的亮度比灯b小,求出每盏灯的亮度,要求字典序最小(编号小的灯亮度尽量小),使之满足m对关系,如果不存在,输出-1 解题思路 每对灯的关系:a b ,说明灯a的亮度比灯b小,同时也说明a的完成时间比b早(AOV网中的概念),这种关系可以用拓扑排序很好地处理,而由于这个题目要求字典序最小,为此将队列改为优先队列,使得编号大的灯先出队,并为其赋予较大的拓扑序,这…
题目大意:原题链接 给出N个未编号的质量各不相同的球,以及它们质量轻重的大小关系,给它们从1-N贴标签编号,无重复.问是否存在可行的编号方法,不存在输出-1, 如果存在则输出唯一一种方案,此方案是使得编号小的球的重量尽量轻,先是编号为1的重量要最轻,其次比编号2,以此类推...... 思路:当解有多组时,编号小的质量尽量小.所以就采用逆拓扑排序(正向的贪心不能完全保证序号小的节点尽量排在前面.仔细思考~~~~~), 按编号从大到小,找质量最大的.这样,小标签就都留给了质量小的.比如4-->1,3…
id=3687">Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10178 Accepted: 2815 Description Windy has N balls of distinct weights from 1 unit toN units. Now he tries to label them with 1 toN in such a way that: No two balls…
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11893 Accepted: 3408 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…
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…
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: 12466   Accepted: 3576 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: 13109   Accepted: 3782 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…
题意:N个球,从1-N编号,质量不同,范围1-N,无重复.给出小球间的质量关系(<), 要求给每个球贴标签,标签表示每个球的质量.按编号输出每个球的标签.如果解不唯一,按编号小的质量小排. /* 被这道题坑惨了,刚开始读错题了,题目要求输出每个球的重量,而不是按重量输出球的编号 还有,因为题目要求如果有多解,则编号小的质量小,因为拓扑排序是按质量从小到大来找, 所以没有什么好的方法,于是反向拓扑,并且倒着找,把质量大的留给编号大的就可以了. */ #include<cstdio> #in…
优先队列 + 反向拓扑 //#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<algorithm> #include<queue> #include<cstring> using namespace std; ; int n, m; vector<int>G[maxn]; int inDeg[maxn]; int dp[maxn]; i…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13645   Accepted: 3955 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 same label…
poj3687:http://poj.org/problem?id=3687 题意:有N个重量1到N的点,把这N个点涂色,要求在一定的约束下颜色a必须比颜色b要轻,如果有多种选择则让重量最小的对应编号1,然后剩下中重量最小的给编号2,一次类推 题解:逆向建图,这样取出来的就是最后选择的点,并标上最大重量,把邻接点入度为0的加入到优先队列中,然后取编号最大的,为的是使得留着编号最小的给重量最大的 #include <iostream> #include <cstdio> #inclu…
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 <…
题目是要给n个重量1到n的球编号,有一些约束条件:编号A的球重量要小于编号B的重量,最后就是要输出字典序最小的从1到n各个编号的球的重量. 正向拓扑排序,取最小编号给最小编号是不行的,不举出个例子真的很难理解= =比如这个数据: 1 4 2 4 1 3 2 正确答案是2 4 3 1,会得到的错误答案是4 2 1 3. 一开始我是用了贪心的做法,每次选未安排重量的最小的编号,安排给它尽量小的重量.某个编号能得到的最小的重量的计算是这样的: 计算出约束中重量要小于此编号的编号个数,记为k,这个可以先…
题目链接. 题目大意: N个球,从1-N编号,质量不同,范围1-N,无重复.给出小球间的质量关系(<), 要求给每个球贴标签,标签表示每个球的质量.按编号输出每个球的标签.如果解不唯一,按编号小的质量小排. 分析: 通过一组数据发现理解错题意了. 1 5 4 1 4 4 2 5 3 3 2答案应当是: 1 5 3 4 2 当解有多组时,编号小的质量小,这一条件不太好用.所以就反向建图,按编号从大到小,找质量最大的.这样,小标签就都留给了编号小的. #include <iostream>…
不一样的拓扑排序 给定一些标记为1到n的数, 求出满足a < b 的序列, 如果有多个输出, 按先标签1往前的位置, 然后按标签2往前的位置, 对于每个标签, 位置都尽量往前. 因为位置要往前,就不能正向建图, 因为正向的拓扑每次在最前的都是最小的点, 并不能保证标签1也在最前面, 比如 1 5 3 4 2 和 1 4 5 3 2 如果按拓扑排序, 答案一定是1 4 5 3 2, 因为4比5小, 但是题目想要各个标签的位置往前, 这样1, 2标签位置一样, 对于3标签, 第一个在3处, 第二个在…