bzoj1924: [Sdoi2010]所驼门王的宝藏
陈年老题又来水一发啊啊啊
构图狗了一点,然后其实强连通缩点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]所驼门王的宝藏的更多相关文章
- BZOJ1924:[SDOI2010]所驼门王的宝藏(强连通分量,拓扑排序)
Description Input 第一行给出三个正整数 N, R, C. 以下 N 行,每行给出一扇传送门的信息,包含三个正整数xi, yi, Ti,表示该传送门设在位于第 xi行第yi列的藏宝宫室 ...
- BZOJ1924 [Sdoi2010]所驼门王的宝藏 【建图 + tarjan】
题目 输入格式 第一行给出三个正整数 N, R, C. 以下 N 行,每行给出一扇传送门的信息,包含三个正整数xi, yi, Ti,表示该传送门设在位于第 xi行第yi列的藏宝宫室,类型为 Ti.Ti ...
- 【BZOJ-1924】所驼门王的宝藏 Tarjan缩点(+拓扑排序) + 拓扑图DP
1924: [Sdoi2010]所驼门王的宝藏 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 787 Solved: 318[Submit][Stat ...
- [BZOJ 1924][Sdoi2010]所驼门王的宝藏
1924: [Sdoi2010]所驼门王的宝藏 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 1285 Solved: 574[Submit][Sta ...
- 【题解】SDOI2010所驼门王的宝藏(强连通分量+优化建图)
[题解]SDOI2010所驼门王的宝藏(强连通分量+优化建图) 最开始我想写线段树优化建图的说,数据结构学傻了233 虽然矩阵很大,但是没什么用,真正有用的是那些关键点 考虑关键点的类型: 横走型 竖 ...
- [SDOI2010]所驼门王的宝藏
题目描述 在宽广的非洲荒漠中,生活着一群勤劳勇敢的羊驼家族.被族人恭称为"先知"的Alpaca L. Sotomon是这个家族的领袖,外人也称其为"所驼门王". ...
- [LuoguP2403][SDOI2010]所驼门王的宝藏
题目描述 在宽广的非洲荒漠中,生活着一群勤劳勇敢的羊驼家族.被族人恭称为"先知"的Alpaca L. Sotomon是这个家族的领袖,外人也称其为"所驼门王". ...
- BZOJ 1924: [Sdoi2010]所驼门王的宝藏 【tarjan】
Description 在宽广的非洲荒漠中,生活着一群勤劳勇敢的羊驼家族.被族人恭称为“先 知”的Alpaca L. Sotomon 是这个家族的领袖,外人也称其为“所驼门王”.所 驼门王毕生致力于维 ...
- 洛谷 2403 [SDOI2010] 所驼门王的宝藏
题目描述 在宽广的非洲荒漠中,生活着一群勤劳勇敢的羊驼家族.被族人恭称为“先知”的Alpaca L. Sotomon是这个家族的领袖,外人也称其为“所驼门王”.所驼门王毕生致力于维护家族的安定与和谐, ...
随机推荐
- java网络通信编程
网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发送到指定的位置,或者接收到指定的数据,这个就是狭义的网络编程范畴.在发送和接收数据时,大部分的程序设计语言都设 ...
- A - Vile Grasshoppers
Problem description The weather is fine today and hence it's high time to climb the nearby pine and ...
- 常用图片、文字轮播插件SuperSlide
SuperSlide 是致力于实现网站统一特效调用的函数,能解决大部分标签切换.焦点图切换等效果,还能多个slide组合创造更多的效果.(兼容ie内核(包括无敌的ie6).webkit内核.ff.op ...
- date 格式化
以这个为例: yyyy-MM-dd HH:mm:ss 首先得写好你需要的模板 options.sign = options.sign || 'yyyy-MM-dd HH:mm:ss'; 其次就可 ...
- CV与IP:基础,经典以及最近发展
原文链接:http://blog.csdn.net/dcraw/article/details/7617891 原文编写层层递进,逻辑清晰: 不过看这篇转载可以少点击鼠标:http://blog.cs ...
- (转) shiro权限框架详解06-shiro与web项目整合(上)
http://blog.csdn.net/facekbook/article/details/54947730 shiro和web项目整合,实现类似真实项目的应用 本文中使用的项目架构是springM ...
- Project Euler 46 Goldbach's other conjecture( 线性筛法 )
题意: 克里斯蒂安·哥德巴赫曾经猜想,每个奇合数可以写成一个素数和一个平方的两倍之和 9 = 7 + 2×1215 = 7 + 2×2221 = 3 + 2×3225 = 7 + 2×3227 = 1 ...
- [NoiPlus2016]换教室
flag++ //Writer : Hsz %WJMZBMR%tourist%hzwer #include <iostream> #include <cstdio> #incl ...
- k8s的概念
Kubernetes(简称为 K8s),最初由 Google 的工程师开发和设计.Kubernetes 是用于自动部署.扩展和管理容器化应用程序的开源系统,它旨在提供跨主机集群的自动部署.扩展以及运行 ...
- 第n个质数
//注:for循环之后第三个式子总会操作一遍. #include <iostream> using namespace std; int main() { int n; while (ci ...