题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/查错

题解:刚开始看见立马以为是 p1790拓扑编号,于是改了下输出就交了。。。

然后就爆零了。。。

仔细看题发现:

本题要求  尽早处理编号小的点

尽量使编号小的点最早被处理

难道不一样?

后来发现了 p1790的样例:

5 4

4 1

1 3

5 3

2 5

然后就明白了

对p1790来说,要想1号尽早被处理,第一次就得处理4

而本题要求处理顺序最小 那么第一次处理的必须得是2

然后就呵呵了

所以这两题的解法分别是:

本题:正向贪心,每次选取入度为0的且编号最小的点

p1790:反向贪心,反向建图,每次选取出度为0且编号最大的点

代码:(本题)

 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 250000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,head[maxn],inp[maxn],ans[maxn],cnt;
struct edge{int go,next;}e[maxn];
priority_queue<int,vector<int>,greater<int> >q;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();
for1(i,m)
{
int x=read(),y=read();
e[i].go=y;e[i].next=head[x];head[x]=i;inp[y]++;
}
for1(i,n)if(!inp[i])q.push(i);
while(!q.empty())
{
int x=q.top();q.pop();ans[++cnt]=x;
for(int i=head[x],y;i;i=e[i].next)
{
inp[y=e[i].go]--;
if(!inp[y])q.push(y);
}
}
if(cnt<n)printf("OMG.\n");else for1(i,n)printf("%d ",ans[i]);
return ;
}

(p1790)

 var head,q,next,go,a,f,outp:array[..] of longint;
i,h,t,n,m,x,y,l,tot:longint;
function get:longint;
var i,k:longint;
begin
get:=a[];
a[]:=a[l];dec(l);
i:=;k:=;
while k<=l do
begin
if (k<l) and (a[k]<a[k+]) then inc(k);
if (a[]<a[k]) then begin a[i]:=a[k];i:=k;k:=k<<;end
else k:=l+;
end;
a[i]:=a[];
end;
procedure put(x:longint);
var i,k:longint;
begin
inc(l);
a[]:=x;
i:=l;k:=l>>;
while k>= do
begin
if a[]>a[k] then begin a[i]:=a[k];i:=k;k:=k>>;end
else k:=;
end;
a[i]:=x;
end;
procedure init;
begin
readln(n,m);
for i:= to m do
begin
readln(x,y);
go[i]:=x;
next[i]:=head[y];
head[y]:=i;
inc(outp[x]);
end;
end;
procedure main;
begin
h:=;t:=;
for i:= to n do
if outp[i]= then
put(i);
tot:=n;
while l<> do
begin
x:=get;
f[x]:=tot;dec(tot);
i:=head[x];
while i<> do
begin
y:=go[i];
dec(outp[y]);
if outp[y]= then put(y);
i:=next[i];
end;
end;
for i:= to n do write(f[i],' ');
end;
begin
init;
main;
end.

   

查错 CH Round #57 - Story of the OI Class的更多相关文章

  1. CH Round #57 - Story of the OI Class 凯撒密码

    很有意思的一道题目 考场上想的是HASH成一个整数,把末位asicc码值*1,依次乘*10,得到一个整数,然后利用等差性.唯一性快排Nlogn乱搞的 证明如下: 对于明文abcde 密文 bcdef ...

  2. 【拓扑排序】【堆】CH Round #57 - Story of the OI Class 查错

    拓扑排序,要让字典序最小,所以把栈改成堆. #include<cstdio> #include<queue> #include<algorithm> using n ...

  3. 导航软件 CH Round #57 - Story of the OI Class

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/导航软件 题解:刚开始看见题目, ...

  4. 凯撒密码 CH Round #57 - Story of the OI Class

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2357%20-%20Story%20of%20the%20OI%20Class/凯撒密码 题解:刚开始想map, ...

  5. CH Round #72树洞[二分答案 DFS&&BFS]

    树洞 CH Round #72 - NOIP夏季划水赛 描述 在一片栖息地上有N棵树,每棵树下住着一只兔子,有M条路径连接这些树.更特殊地是,只有一棵树有3条或更多的路径与它相连,其它的树只有1条或2 ...

  6. CH Round #52 还教室[线段树 方差]

    还教室 CH Round #52 - Thinking Bear #1 (NOIP模拟赛) [引子]还记得 NOIP 2012 提高组 Day2 中的借教室吗?时光飞逝,光阴荏苒,两年过去了,曾经借教 ...

  7. CH Round #30 摆花[矩阵乘法]

    摆花 CH Round #30 - 清明欢乐赛 背景及描述 艺术馆门前将摆出许多花,一共有n个位置排成一排,每个位置可以摆花也可以不摆花.有些花如果摆在相邻的位置(隔着一个空的位置不算相邻),就不好看 ...

  8. 使用DBUnit框架数据库插入特殊字符失败的查错经历

    本文记录的是使用DBUnit测试框架进行数据库数据插入时,插入特殊字符失败的查错经历.希望能对向我这样的小白同学们在遇到类似问题时,能够有一些启发.背景:在写跟数据库交互模块的单元测试,数据库表中的e ...

  9. contesthunter CH Round #64 - MFOI杯水题欢乐赛day1 solve

    http://www.contesthunter.org/contest/CH Round %2364 - MFOI杯水题欢乐赛 day1/Solve Solve CH Round #64 - MFO ...

随机推荐

  1. eslint error

    暂时不想解决 报错: 3:16 error Component should be written as a pure function react/prefer-stateless-function ...

  2. 第二篇:python高级之装饰器

    python高级之装饰器   python高级之装饰器 本节内容 高阶函数 嵌套函数及闭包 装饰器 装饰器带参数 装饰器的嵌套 functools.wraps模块 递归函数被装饰 1.高阶函数 高阶函 ...

  3. Array,ArrayList 和 List<T>的选择和性能比较.

    Array Class Provides methods for creating, manipulating, searching, and sorting arrays, thereby serv ...

  4. C#中区别多态、重载、重写的概念和语法结构

    C#中区别多态.重载.重写的概念和语法结构 重写是指重写基类的方法,在基类中的方法必须有修饰符virtual,而在子类的方法中必须指明override. 格式: 基类中: public virtual ...

  5. 从ActionFilterAttribute向view传送数据

    [原文转载]http://www.cnblogs.com/QLeelulu/archive/2008/08/17/1269599.html 原文地址:ASP.NET MVC Tip #31 – Pas ...

  6. Orace数据库锁表的处理与总结<摘抄与总结二>

    当Oracle数据库发生TX锁等待时,如果不及时处理常常会引起Oracle数据库挂起,或导致死锁的发生,产生ORA-60的错误. TX锁等待的分析 Oracle数据库中一般使用行级锁. 当Oracle ...

  7. acl操作记录

    官方文档内容: 1.CREATE_ACL Procedure创建ACL Note: This procedure is deprecated in Oracle Database 12c. While ...

  8. NSString 的三种截取方法

    1.定义一个字符串a, 截取a 的某一个项目组,复制给b, b必须是int型 NSString *a = @"1.2.30"; int  b= [[a substringWithR ...

  9. office2010怎么激活

    软件都是不断更新换代的,像我们使用最多的Microsoft Office软件,从最初的98,2000,2003,2007,到现在的2010.但是在最初安装Office软件时,都是未激活的.下面介绍的就 ...

  10. CSS布局模型思考

    flow模型:默认布局模型,元素从左向右.从上到下依次排列,块状元素独占一行.Position属性对应值static. float模型:主要效果是让本来独占一行的块状元素变成内联-块状元素,并到一排显 ...