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【拓扑排序】的更多相关文章

  1. 求拓扑排序的数量,例题 topcoder srm 654 div2 500

    周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are number ...

  2. 算法与数据结构(七) AOV网的拓扑排序

    今天博客的内容依然与图有关,今天博客的主题是关于拓扑排序的.拓扑排序是基于AOV网的,关于AOV网的概念,我想引用下方这句话来介绍: AOV网:在现代化管理中,人们常用有向图来描述和分析一项工程的计划 ...

  3. 有向无环图的应用—AOV网 和 拓扑排序

    有向无环图:无环的有向图,简称 DAG (Directed Acycline Graph) 图. 一个有向图的生成树是一个有向树,一个非连通有向图的若干强连通分量生成若干有向树,这些有向数形成生成森林 ...

  4. 【BZOJ-2938】病毒 Trie图 + 拓扑排序

    2938: [Poi2000]病毒 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 609  Solved: 318[Submit][Status][Di ...

  5. BZOJ1565 [NOI2009]植物大战僵尸(拓扑排序 + 最大权闭合子图)

    题目 Source http://www.lydsy.com/JudgeOnline/problem.php?id=1565 Description Input Output 仅包含一个整数,表示可以 ...

  6. 图——拓扑排序(uva10305)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  7. Java排序算法——拓扑排序

    package graph; import java.util.LinkedList; import java.util.Queue; import thinkinjava.net.mindview. ...

  8. poj 3687(拓扑排序)

    http://poj.org/problem?id=3687 题意:有一些球他们都有各自的重量,而且每个球的重量都不相同,现在,要给这些球贴标签.如果这些球没有限定条件说是哪个比哪个轻的话,那么默认的 ...

  9. 拓扑排序 - 并查集 - Rank of Tetris

    Description 自从Lele开发了Rating系统,他的Tetris事业更是如虎添翼,不久他遍把这个游戏推向了全球. 为了更好的符合那些爱好者的喜好,Lele又想了一个新点子:他将制作一个全球 ...

随机推荐

  1. android kotlin Gradle DSL method not found: '1.2.51()'错误,be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).

    同步的时候遇到这个问题,从log上看是因为gradle的版本不包含kotlin 1.2.51这个method,具体原因我也不是很清楚,大概猜测是kotlin版本的问题,而最新的版本就是1.2.51,所 ...

  2. python学习笔记8--面向对象编程

    一.面向对象编程 面向对象--Object Oriented Programming,简称oop,是一种程序设计思想.在说面向对象之前,先说一下什么是编程范式,编程范式你按照什么方式来去编程,去实现一 ...

  3. VUE2.0 饿了吗视频学习笔记(三):VUE2.0取消了v-link

    https://gitee.com/1981633/vue_study.git 源码下载地址,随笔记动态更新中 写法如下 <div class="tab-item"> ...

  4. 深度神经网络tricks and tips

    1)data augmentation (augment 增加,aug:to increase 词根,同August(奥古斯特即凯撒大帝,自认为最伟大的帝王,他出生在八月,他以自己的名字命名这个月)同 ...

  5. QDoubleSpinBox浮点型数字调节框

    样式: import sys from PyQt5.QtWidgets import QApplication, QWidget, QDoubleSpinBox class Demo(QWidget) ...

  6. pygame设置text和image共同显示

    下面介绍一下如何用pygame将text文本和图片一起绑定到视图 部分重点用不同颜色做了标记,希望对大家有帮助 代码块: %%writefile tranformtouxiang2.py import ...

  7. 关于apache 开启 ssl https 支持 TLS1.2 的些事

    项目背景 需要搭建一个小程序的服务器,当然要使用https协议服务器windows service 2012 r2,后台语言是php,服务集成环境装的是appserv2.5 ,apache2.2证书申 ...

  8. sql 查询名字中有_的员工

    select * from emp where ename like '%\_%' escape '\' ;\可以换作任意的字符 select * from emp where ename like ...

  9. TeamCity 和 Nexus 的使用

    参考:http://www.jianshu.com/p/255a484555d9 TeamCity 安装部署(Linux 环境) 在我讲之前,如果你英文还可以,就到官网这里看下: Installati ...

  10. ubuntu14.04 + cuda8.0 + cudnnv5 + caffe + py-faster-rcnn配置

    经过几天的奋战终于配置好了如题所述的配置,现在把配置大体过程写下来供大家配置时参考(由于电脑硬件和系统的千差万别,实在不适合写详细的) (一切不声明配置环境的配置教程都是耍流氓) 环境: Inter集 ...