陈年老题又来水一发啊啊啊

构图狗了一点,然后其实强连通缩点dij找最长路就没了。

没调出来有点气,直接打了第9个点的表。。。。

来逛blog的你教教我呗

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
using namespace std;
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;
} struct node
{
int x,y,next;
}e[];int elen,elast[];
void eins(int x,int y)
{
elen++;
e[elen].x=x;e[elen].y=y;
e[elen].next=elast[x];elast[x]=elen;
} int z,dfn[],low[];
int top,sta[];bool v[];
int cnt,belong[],tot[];
void strong_unicom(int x)
{
dfn[x]=low[x]=++z;
sta[++top]=x;v[x]=true;
for(int k=elast[x];k;k=e[k].next)
{
int y=e[k].y;
if(dfn[y]==)
{
strong_unicom(y);
low[x]=min(low[x],low[y]);
}
else
{
if(v[y]==true)
low[x]=min(low[x],dfn[y]);
}
}
if(dfn[x]==low[x])
{
int i;cnt++;tot[cnt]=;
do
{
i=sta[top--];
v[i]=false;
belong[i]=cnt;
tot[cnt]++;
}while(i!=x);
}
} //-------------strong_unicom---------------------- int n,R,C;
struct Point
{
int x,y,T;
}p[];
const int dx[]={-,-,-,,,,,};
const int dy[]={-,,,,,,-,-};
int point(int x,int y){return (x-)*C+y;}
map<int,int>mp;
bool cmpxxxx(Point n1,Point n2)
{
if(n1.x==n2.x)
{
if(n1.T==n2.T||(n1.T!=&&n2.T!=))return n1.y<n2.y;
else if(n1.T==)return true;
else if(n2.T==)return false;
}
else return n1.x<n2.x;
}
bool cmpyyyy(Point n1,Point n2)
{
if(n1.y==n2.y)
{
if(n1.T==n2.T||(n1.T!=&&n2.T!=))return n1.x<n2.x;
else if(n1.T==)return true;
else if(n2.T==)return false;
}
else return n1.y<n2.y;
} //-----------------composition-------------------- node a[];
int len,last[];
void ins(int x,int y)
{
len++;
a[len].x=x;a[len].y=y;
a[len].next=last[x];last[x]=len;
} int st,ed,d[];
struct Dij
{
int x;
bool friend operator <(Dij n1,Dij n2){return d[n1.x]>d[n2.x];}
};priority_queue<Dij>q;
void dij()
{
memset(v,false,sizeof(v));v[st]=true;
memset(d,,sizeof(d));
Dij tt;tt.x=st;
q.push(tt);
while(!q.empty())
{
int x=q.top().x;q.pop();
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(d[y]<d[x]+tot[y])
{
d[y]=d[x]+tot[y];
if(v[y]==false)
{
v[y]=true;
tt.x=y;
q.push(tt);
}
}
}
v[x]=false;
}
printf("%d\n",d[ed]);
} int main()
{
freopen("sotomon.in","r",stdin);
freopen("sotomon.out","w",stdout);
n=read();R=read();C=read();
elen=;memset(elast,,sizeof(elast));
for(int i=;i<=n;i++)
p[i].x=read(), p[i].y=read(),p[i].T=read(), mp[point(p[i].x,p[i].y)]=i;
for(int i=;i<=n;i++)
{
if(p[i].T==)
{
for(int k=;k<=;k++)
{
int tx=p[i].x+dx[k],ty=p[i].y+dy[k];
if(tx>&&tx<=R&&ty>&&ty<=C&&mp[point(tx,ty)]!=)
eins(i,mp[point(tx,ty)]);
}
}
}
int tp;
sort(p+,p+n+,cmpxxxx);
for(int i=;i<=n;i=tp+)
{
tp=i;
if(p[i].T==)
for(int j=i+;p[i].x==p[j].x&&i<=n;j++)
{
eins(mp[point(p[i].x,p[i].y)],mp[point(p[j].x,p[j].y)]);
if(p[j].T==)
eins(mp[point(p[j].x,p[j].y)],mp[point(p[i].x,p[i].y)]);
tp=j;
}
}
sort(p+,p+n+,cmpyyyy);
for(int i=;i<=n;i=tp+)
{
tp=i;
if(p[i].T==)
for(int j=i+;p[i].y==p[j].y&&i<=n;j++)
{
eins(mp[point(p[i].x,p[i].y)],mp[point(p[j].x,p[j].y)]);
if(p[j].T==)
eins(mp[point(p[j].x,p[j].y)],mp[point(p[i].x,p[i].y)]);
tp=j;
}
} //-------------------sc&&composition----------------------------- z=top=cnt=;
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(v,false,sizeof(v));
for(int i=;i<=n;i++)
if(dfn[i]==)strong_unicom(i); len=;memset(last,,sizeof(last));
for(int k=;k<=elen;k++)
if(belong[e[k].x]!=belong[e[k].y])
ins(belong[e[k].x],belong[e[k].y]);
st=cnt+;ed=cnt+;
for(int i=;i<=cnt;i++)ins(st,i),ins(i,ed);
dij(); return ;
}

bzoj1924: [Sdoi2010]所驼门王的宝藏的更多相关文章

  1. BZOJ1924:[SDOI2010]所驼门王的宝藏(强连通分量,拓扑排序)

    Description Input 第一行给出三个正整数 N, R, C. 以下 N 行,每行给出一扇传送门的信息,包含三个正整数xi, yi, Ti,表示该传送门设在位于第 xi行第yi列的藏宝宫室 ...

  2. BZOJ1924 [Sdoi2010]所驼门王的宝藏 【建图 + tarjan】

    题目 输入格式 第一行给出三个正整数 N, R, C. 以下 N 行,每行给出一扇传送门的信息,包含三个正整数xi, yi, Ti,表示该传送门设在位于第 xi行第yi列的藏宝宫室,类型为 Ti.Ti ...

  3. 【BZOJ-1924】所驼门王的宝藏 Tarjan缩点(+拓扑排序) + 拓扑图DP

    1924: [Sdoi2010]所驼门王的宝藏 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 787  Solved: 318[Submit][Stat ...

  4. [BZOJ 1924][Sdoi2010]所驼门王的宝藏

    1924: [Sdoi2010]所驼门王的宝藏 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 1285  Solved: 574[Submit][Sta ...

  5. 【题解】SDOI2010所驼门王的宝藏(强连通分量+优化建图)

    [题解]SDOI2010所驼门王的宝藏(强连通分量+优化建图) 最开始我想写线段树优化建图的说,数据结构学傻了233 虽然矩阵很大,但是没什么用,真正有用的是那些关键点 考虑关键点的类型: 横走型 竖 ...

  6. [SDOI2010]所驼门王的宝藏

    题目描述 在宽广的非洲荒漠中,生活着一群勤劳勇敢的羊驼家族.被族人恭称为"先知"的Alpaca L. Sotomon是这个家族的领袖,外人也称其为"所驼门王". ...

  7. [LuoguP2403][SDOI2010]所驼门王的宝藏

    题目描述 在宽广的非洲荒漠中,生活着一群勤劳勇敢的羊驼家族.被族人恭称为"先知"的Alpaca L. Sotomon是这个家族的领袖,外人也称其为"所驼门王". ...

  8. BZOJ 1924: [Sdoi2010]所驼门王的宝藏 【tarjan】

    Description 在宽广的非洲荒漠中,生活着一群勤劳勇敢的羊驼家族.被族人恭称为“先 知”的Alpaca L. Sotomon 是这个家族的领袖,外人也称其为“所驼门王”.所 驼门王毕生致力于维 ...

  9. 洛谷 2403 [SDOI2010] 所驼门王的宝藏

    题目描述 在宽广的非洲荒漠中,生活着一群勤劳勇敢的羊驼家族.被族人恭称为“先知”的Alpaca L. Sotomon是这个家族的领袖,外人也称其为“所驼门王”.所驼门王毕生致力于维护家族的安定与和谐, ...

随机推荐

  1. css中max-width和min-width的应用

    max-width:从字面意思可以看出,是规定元素本身最大宽度,元素本身宽度应小于等于最大宽度值. min-width:从字面意思可以看出,是规定元素本身最小宽度,元素本身宽度应大于等于最小宽度值. ...

  2. 洛谷P2455 [SDOI2006]线性方程组(高斯消元)

    题目描述 已知n元线性一次方程组. 其中:n<=50, 系数是[b][color=red]整数<=100(有负数),bi的值都是整数且<300(有负数)(特别感谢U14968 mmq ...

  3. 关于安卓调用wcf的一些问题

    最近公司有个项目需要和别的系统做对接,对方开放的是webservice接口,搞了很久终于搞出来了,在此记录一下 获取数据的service public class SoapService implem ...

  4. 【Oracle】ORA-38171: Insufficient privileges for SQL management object operation

    问题: 使用SQL PLAN MANAGEMENT的时候运行下面的存储过程报错. SYS@GOOD> conn scott/tiger Connected. SCOTT@GOOD> DEC ...

  5. VHDL之Aggregate

    Definition A basic operation that combines one or more values into a composite value of a record or ...

  6. bootstrap初用新得1

    ## 基本准备 1. 首先把相关软件窗口规划好,对于我的喜好,我喜欢把除了浏览器外的其他软件分为左右两个半屏.左边和右边很多软件之间是需要配合使用的:     * 左边: scss文件,ps的guid ...

  7. JDK源码中的英文注释翻译(Class)

    public final class Class<T> implements java.io.Serializable, GenericDeclaration, Type, Annotat ...

  8. Django 的 一些基本操作:视图函数,路由配置

    当安装好Django 通过上篇的随笔创好项目我们就能来耍下了, 但你会在你的项目中发现有一个settings.py 的文件,对的你肯定想到了需要配置,好了话不多说 Settings.py 找到下面的位 ...

  9. VMware VCSA 6.0安装过程 (转)

    VMware VCSA 6.0安装过程(专版)  一.环境准备   VMware vCenter Server Appliance(VCSA)6.0的部署和之前的版本不同,在5.5及之前的版本可以通过 ...

  10. Substring Uva 11468_记忆化搜索 + AC自动机

    Code: #include<cstdio> #include<cstring> #include<queue> using namespace std; cons ...