TopCoder FlowerGarden【拓扑排序】
https://community.topcoder.com/stat?c=problem_statement&pm=1918&rd=5006
拓扑排序,每次选择最大的就好了
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h> #define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
using namespace std; struct edge{
int to;
int next;
}E[2050]; class FlowerGarden
{
public:
int n;
int ip;
int in[1005];//入度
int head[1005];//邻接顶点
void init()
{
ip=0;
cle(in);
memset(head,-1,sizeof(head));
}
void add(int x,int y){
in[y]++;
E[ip].to=y;
E[ip].next=head[x];
head[x]=ip++;
}
vector <int> getOrdering(vector <int> height, vector <int> bloom, vector <int> wilt)
{
n=height.size();
int i,j,k;
vector<int> ans;
ans.clear();
init();
rep(i,n){
rep(j,n){//有序枚举
if(i==j)continue;
if(height[i]<height[j]){
if(!((wilt[j]<bloom[i])||(bloom[j]>wilt[i])))
add(height[i],height[j]);
}
}
}
int used[1500];cle(used);
for(i=1;i<=n;i++)
{
int maxnum=0;
for(j=0;j<n;j++)
{
if(used[height[j]])continue;
if(in[height[j]]==0)
{
maxnum=max(maxnum,height[j]);
}
//break;
}
used[maxnum]=1;
ans.push_back(maxnum);
for(k=head[maxnum];k!=-1;k=E[k].next)in[E[k].to]--;
}
return ans;
}
};
TopCoder FlowerGarden【拓扑排序】的更多相关文章
- 求拓扑排序的数量,例题 topcoder srm 654 div2 500
周赛时遇到的一道比较有意思的题目: Problem Statement There are N rooms in Maki's new house. The rooms are number ...
- 算法与数据结构(七) AOV网的拓扑排序
今天博客的内容依然与图有关,今天博客的主题是关于拓扑排序的.拓扑排序是基于AOV网的,关于AOV网的概念,我想引用下方这句话来介绍: AOV网:在现代化管理中,人们常用有向图来描述和分析一项工程的计划 ...
- 有向无环图的应用—AOV网 和 拓扑排序
有向无环图:无环的有向图,简称 DAG (Directed Acycline Graph) 图. 一个有向图的生成树是一个有向树,一个非连通有向图的若干强连通分量生成若干有向树,这些有向数形成生成森林 ...
- 【BZOJ-2938】病毒 Trie图 + 拓扑排序
2938: [Poi2000]病毒 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 609 Solved: 318[Submit][Status][Di ...
- BZOJ1565 [NOI2009]植物大战僵尸(拓扑排序 + 最大权闭合子图)
题目 Source http://www.lydsy.com/JudgeOnline/problem.php?id=1565 Description Input Output 仅包含一个整数,表示可以 ...
- 图——拓扑排序(uva10305)
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- Java排序算法——拓扑排序
package graph; import java.util.LinkedList; import java.util.Queue; import thinkinjava.net.mindview. ...
- poj 3687(拓扑排序)
http://poj.org/problem?id=3687 题意:有一些球他们都有各自的重量,而且每个球的重量都不相同,现在,要给这些球贴标签.如果这些球没有限定条件说是哪个比哪个轻的话,那么默认的 ...
- 拓扑排序 - 并查集 - Rank of Tetris
Description 自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球 ...
随机推荐
- 常用关于Android活动的实践技巧
//知晓当前是在哪一个活动 /* 新建一个BaseActivity类(Java class), 继承自AppCompatActivity * 重写 onCreate()方法,已有的活动无需再继承自Ap ...
- IDA Pro使用技巧
DA Pro基本简介 IDA加载完程序后,3个立即可见的窗口分别为IDA-View,Named,和消息输出窗口(output Window). IDA图形视图会有执行流,Yes箭头默认为绿色,No箭头 ...
- 20155204 2016-2017-2 《Java程序设计》第6周学习总结
20155204 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 一切皆对象,输入输出也是类,线程也是 String对象的trim方法去掉首尾空格和空字符 f ...
- matplotlib-2D绘图库
安装 python -m pip install matplotlib 允许中文: 使用matplotlib的字体管理器指定字体文件 plt.rcParams['font.sans-serif'] ...
- JavaScript之不规则Table转化为可定点索引td节点的网格矩阵【插件】
由于解析课程表的缘故,有如下需求: 1. 将任意表格解析成独立的单元格矩阵[本次博文的缘由] 2. 根据矩阵坐标,确定任意一格的节点 /* 表格-->网格化 标记表格的位置及其对应的节点 * ...
- CF115B Lawnmower(贪心)
CF115B Lawnmower \(solution:\) 很明显的一道贪心题,奇数行只能向左走,偶数行只能向右走,每一行的起点应该在上一行就已确定,而这一行的终点只和(这一行最后一棵草(相对于你走 ...
- IE8以下浏览器设置Title的问题
ie8不支持网页title的如下写法 $('title').text('标题'); $('title').html('标题'); 在ie8中,正确写法: document.title = &quo ...
- python 错误: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
参照:http://www.runoob.com/django/django-form.html 做了个表单提交和回显,但是报了以上错误 查资料发现是 python从request取值的是unicod ...
- SpringBoot定制错误的Json数据
(1)自定义异常处理&返回定制Json数据 @ControllerAdvice public class MyExceptionHandler { @ResponseBody @Excepti ...
- 【转】Python介绍
[转]Python介绍 本节内容 Python简史 Python是一门什么样的语言? Python的优点与缺点 Python解释器 一.Python简史 历史背景 在20世纪80年代,IBM和苹果已经 ...