题目: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. VS2012减负:加快启动速度,减少编辑卡壳

    我公司的笔记本配置如下: CPU:i5-3210M @ 2.50 GHz 2.50 GHz mem: 4.00 GB OS: 64bit Win7 用VS2012编译Cocos2d-X项目时非常的卡. ...

  2. svn命令的使用

    1.检出svn  co  http://路径(目录或文件的全路径) [本地目录全路径] --username 用户名 --password 密码svn  co  svn://路径(目录或文件的全路径) ...

  3. jersey + tomcat 实现restful风格

    本文参考 http://www.cnblogs.com/bluesfeng/archive/2010/10/28/1863816.html 环境: idea 15.0.2 jersey 1.3 tom ...

  4. Charles --- Mac 抓包工具

    安装 官方网站Charles 是一款收费软件,可以免费体验30天.网上有破解版. 使用 infoq 上有一篇很棒的教程:iOS开发工具——网络封包分析工具Charles 注意事项 这是我使用过程中遇到 ...

  5. GOOGLE搜索從入門到精通V4.0

    1,前言2,摘要3,如何使用本文4,Google簡介5,搜索入門6,初階搜索 6.1,搜索結果要求包含兩個及兩個以上關鍵字 6.2,搜索結果要求不包含某些特定資訊 6.3,搜索結果至少包含多個關鍵字中 ...

  6. jQuery循环给某个ID赋值

    1.id名为sl的input框循环赋值 $("input[id=sl]").each(function(){alert(this.value) })

  7. PL/SQL 触发器简介

    与公司同事交流了一下,得知触发器很少用.性能是一方面,主要是如果用太多触发器,可能到时你都不知道会有什么操作自动发生. 有些操作可以在程序中控制.例如在插入某个表时,写个log表的记录.这可以用触发器 ...

  8. 把Excel数据导入到数据库

    引入命名空间 using System.IO; using System.Data; using System.Data.OleDb; 引入命名空间 首先要把Excel上传到服务器 //上传Excel ...

  9. Android开发--二维码开发应用(转载!)

    android项目开发 二维码扫描   基于android平台的二维码扫描项目,可以查看结果并且链接网址 工具/原料 zxing eclipse 方法/步骤   首先需要用到google提供的zxin ...

  10. 分离数据库(Detach database).

    Many times, we often needs to detach our databases if we want to copy it to another database instanc ...