CEOI 2011Traffic

首先这个题它给定我们的是一个平面图。(除端点外,没有相交的边)

那么我们可以知道对于: 

每一个在左侧的点 能够到达的 右侧的点一定是一段区间(对应的是y值)。

因为如果区间中有一个点它无法到达,那么其他点必然也无法到那个点,否则会相交。

这样的话我们可以先从左边BFS一遍,如果右边有无法到的点,就不管了。

然后我们考虑怎么求这一段区间。

我们发现可以只需要维护区间的上界和下界就好了。

那么我们把右侧的点按y降序排列,从上往下依次BFS。

每个点第一次被经过时,此时对应的右侧的点,一定是其上界。

同理,从下往上BFS,也可以得到下界。

值得注意的是,我没有额外把那些不符合条件的点去掉,而是把它对于区间的贡献看成0,做了个前缀和。

#include <string>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#define RG register
using namespace std;

inline int gi () {
    int x=0,w=0; char ch=0;
    while (ch<'0' || ch>'9') {if (ch=='-') w=1; ch=getchar ();}
    while (ch>='0' && ch<='9') x=(x<<3)+(x<<1)+(ch^48), ch=getchar ();
    return w?-x:x;
}

const int N=3e5+10;
const int M=9e5+10;

queue <int> q;
int xx[M],yy[M],typ[M];
int tot,head[N],next[M<<1],to[M<<1];
int n,m,A,B,Wcnt,Ecnt,Minx[N],Maxx[N],pre[N],vis[N],arr[N];

struct Dot {int id,y;} Wes[N],Eas[N];
inline bool CMPmax (Dot a, Dot b) {return a.y>b.y;}

inline void make (int from, int To) {       
    next[++tot]=head[from];
    head[from]=tot; to[tot]=To;
}

inline void Clear_Graph () {
    tot=0;
    memset (to, 0, sizeof (to));
    memset (next, 0, sizeof (next));
    memset (head, 0, sizeof (head));
}

inline void BFS_TO () {
    RG int i,x,y;
    for (i=1;i<=Wcnt;++i) arr[Wes[i].id]=1, q.push (Wes[i].id);
    while (!q.empty ()) {
        x=q.front (), q.pop ();
        for (i=head[x];i;i=next[i])
            if (!arr[y=to[i]]) arr[y]=1, q.push (y);
    }
}

inline void BFS_uplim (int x) {
    RG int i,Nx,y;
    q.push (Eas[x].id), vis[Eas[x].id]=1;
    while (!q.empty ()) {
        Nx=q.front (), q.pop ();
        for (i=head[Nx];i;i=next[i])
            if (!vis[y=to[i]]) vis[y]=1, Minx[y]=x, q.push (y);
    }
}

inline void BFS_downlim (int x) {
    RG int i,Nx,y;
    q.push (Eas[x].id), vis[Eas[x].id]=1;
    while (!q.empty ()) {
        Nx=q.front (), q.pop ();
        for (i=head[Nx];i;i=next[i])
            if (!vis[y=to[i]]) vis[y]=1, Maxx[y]=x, q.push (y);
    }
}

int main ()
{
    RG int i,x,y;
    n=gi (), m=gi (), A=gi (), B=gi ();
    for (i=1;i<=n;++i) {
        x=gi (), y=gi ();
        if (x==0) Wes[++Wcnt].y=y, Wes[Wcnt].id=i;
        if (x==A) Eas[++Ecnt].y=y, Eas[Ecnt].id=i;
    }
    for (i=1;i<=m;++i) {
        xx[i]=gi (), yy[i]=gi (), typ[i]=gi ();
        make (xx[i], yy[i]);
        if (typ[i]==2) make (yy[i], xx[i]);
    }
    BFS_TO (); Clear_Graph ();
    for (i=1;i<=m;++i) {
        make (yy[i], xx[i]);
        if (typ[i]==2) make (xx[i], yy[i]);
    }
    sort (Wes+1, Wes+Wcnt+1, CMPmax);
    sort (Eas+1, Eas+Ecnt+1, CMPmax);
    for (i=1;i<=Ecnt;++i)
        pre[i]=arr[Eas[i].id]?pre[i-1]+1:pre[i-1];
    //for (i=1;i<=Ecnt;++i) printf ("%d %d\n", pre[i], Eas[i].id); 
    for (i=1;i<=Ecnt;++i)
        if (arr[Eas[i].id]) BFS_uplim (i);
    //for (i=1;i<=n;++i) printf ("%d ", Minx[i]); puts ("");
    memset (vis, 0, sizeof (vis));
    for (i=Ecnt;i>=1;--i)
        if (arr[Eas[i].id]) BFS_downlim (i);
//    for (i=1;i<=n;++i) printf ("%d ", Maxx[i]); puts ("");
    for (i=1;i<=Wcnt;++i) printf ("%d\n", pre[Maxx[Wes[i].id]]-pre[Minx[Wes[i].id]-1]);
    return 0;
}

 

转载于:https://www.cnblogs.com/Bhllx/p/9863773.html

Stkcd [股票代码] ShortName [股票简称] Accper [统计截止日期] Typrep [报表类型编码] Indcd [行业代码] Indnme [行业名称] Source [公告来源] F060101B [净利润现金净含量] F060101C [净利润现金净含量TTM] F060201B [营业收入现金含量] F060201C [营业收入现金含量TTM] F060301B [营业收入现金净含量] F060301C [营业收入现金净含量TTM] F060401B [营业利润现金净含量] F060401C [营业利润现金净含量TTM] F060901B [筹资活动债权人现金净流量] F060901C [筹资活动债权人现金净流量TTM] F061001B [筹资活动股东现金净流量] F061001C [筹资活动股东现金净流量TTM] F061201B [折旧摊销] F061201C [折旧摊销TTM] F061301B [公司现金流1] F061302B [公司现金流2] F061301C [公司现金流TTM1] F061302C [公司现金流TTM2] F061401B [股权现金流1] F061402B [股权现金流2] F061401C [股权现金流TTM1] F061402C [股权现金流TTM2] F061501B [公司自由现金流(原有)] F061601B [股权自由现金流(原有)] F061701B [全部现金回收率] F061801B [营运指数] F061901B [资本支出与折旧摊销比] F062001B [现金适合比率] F062101B [现金再投资比率] F062201B [现金满足投资比率] F062301B [股权自由现金流] F062401B [企业自由现金流] Indcd1 [行业代码1] Indnme1 [行业名称1] 季度数据,所有沪深北上市公司的 分别包含excel、dta数据文件格式及其说明,便于不同软件工具对数据的分析应用 数据来源:基于上市公司年报及公告数据整理,或相关证券交易所、各部委、省、市数据 数据范围:基于沪深北证上市公司 A股(主板、中小企业板、创业板、科创板等)数据整理计算
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值