[SCOI2003]蜘蛛难题
题目
对于当年来说似乎是神题??
做法
对于联通注水来说,我们考虑把所有能平分到水的桶同时加高度,然后暴力判断
My complete code
copy来的代码
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N=105;
const int INF=32083208;
struct edge {int x,y,next;} b[N];
struct point {int x,y,h;} c[N],pos;
int n,m,a[N],tot,ans,q[N]; bool v[N];
inline long long getint()
{
long long x=0; char c=getchar(); bool flag=false;
while ((c!='-')&&((c<'0')||(c>'9'))) c=getchar();
if (c=='-') flag=true,c=getchar();
while ((c>='0')&&(c<='9')) x=x*10+(long long)(c-'0'),c=getchar();
if (flag) return -x; else return x;
}
inline int find(int x)
{
for (int i=1; i<=n; i++) if (x==c[i].x) return i;
return 0;
}
inline void addedge(int x,int y,int z)
{
++tot; b[tot].x=y; b[tot].y=z; b[tot].next=a[x]; a[x]=tot;
++tot; b[tot].x=x; b[tot].y=z; b[tot].next=a[y]; a[y]=tot;
}
void init()
{
n=getint(); ans=0; tot=0; memset(a,0,sizeof(a));
for (int i=1; i<=n; i++) c[i].x=getint(),c[i].y=getint(),c[i].h=c[i].y+getint(); m=getint();
for (int i=1; i<=m; i++)
{
int x=getint(),y=getint(),d=getint();
addedge(find(x-1),find(x+d),y);
}
pos.x=getint(); pos.y=getint();
}
void bfs()
{
int head=0,tail=0;
for (int i=1; i<=n; i++) if (v[i]) q[++tail]=i;
while (head<tail)
{
int k=q[++head];
for (int p=a[k];p;p=b[p].next)
{
int pp=b[p].x; if (v[pp]) continue;
if (c[k].h<=b[p].y) v[pp]=true,q[++tail]=pp;
}
}
}
void solve()
{
memset(v,false,sizeof(v)); v[1]=true;
while (true)
{
bfs(); int maxh=-INF;
for (int i=1; i<=n; i++) if (v[i]) maxh=max(maxh,c[i].h);
if ((v[pos.x])&&(c[pos.x].h==maxh)&&(c[pos.x].h==pos.y)) {printf("%d\n",ans); return;}
for (int i=1; i<=n; i++) if ((v[i])&&(c[i].h==maxh)&&(c[i].h==c[i].y)) {printf("-1\n"); return;}
for (int i=1; i<=n; i++) if ((v[i])&&(c[i].h==maxh)) c[i].h--,ans++;
}
}
int main()
{
init();
solve();
return 0;
}
[SCOI2003]蜘蛛难题的更多相关文章
- BZOJ1092 : [SCOI2003]蜘蛛难题
按时间一步一步模拟. 每一次,首先将所有没有水但是可以被灌到水的管子标记为有水,然后求出有水的管子里水面高度的最小值. 如果$a$号管有水且最小值为$b$,那么说明此时蜘蛛碰到了水. 如果有管子溢出且 ...
- 【SCOI2003】【BZOJ1092】蜘蛛难题
有一堆管道,还有一个蜘蛛Willy,如下图所示.所有管道的是上端开口,下端封底,直径都是1cm,连接两个管道的连接容量无限,但体积可以忽略不计. 在第一个管道上方有一个水源,从中有水不断往下流,速度为 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 探讨webapp的SEO难题(上)
前言 网络蜘蛛无法解析javascript,至少百度是不能的,神马搜索差的更远,而我们的webapp的渲染展示完全由javascript驱动 所以蜘蛛访问webapp页面会得到一个白页面,比如,我们期 ...
- c#蜘蛛
C#写一个采集器 using System; using System.Collections.Generic; using System.Text; using System.Net; using ...
- 深入super,看Python如何解决钻石继承难题 【转】
原文地址 http://www.cnblogs.com/testview/p/4651198.html 1. Python的继承以及调用父类成员 python子类调用父类成员有2种方法,分别是普通 ...
- 判断来防ip是否为蜘蛛
判断网站来防IP是否为蜘蛛,用命令查询 : 一.在windows平台 蜘蛛反查命令:nslookup IP 点击"开始"-"运行"-"cmd& ...
- BZOJ1090: [SCOI2003]字符串折叠
区间dp. 一种是分段dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]); 一种是这一段可以缩写dp[i][j]=min(dp[i][j],dp[i][l]+2+ca ...
- 一起来做webgame,《Javascript蜘蛛纸牌》
不得不说,做游戏是会上瘾的,这次带来的是win系统上的经典游戏<蜘蛛纸牌>,不能完美,但求一玩 移牌 0 次 Javascript game_蜘蛛纸牌 正在努力加载... // " ...
随机推荐
- BitMap、Geo、HyperLogLog
前言 Reids 在 Web 应用的开发中使用非常广泛,几乎所有的后端技术都会有涉及到 Redis 的使用.Redis 种除了常见的字符串 String.字典 Hash.列表 List.集合 Set. ...
- Spring MVC3.0.5搭建全程
http://aokunsang.iteye.com/blog/1279322 ——————————————————————————————————————————————————
- Spring MVC文本框
以下示例显示如何使用Spring Web MVC框架在表单中使用文本框.首先使用Eclipse IDE来创建一个Web工程,按照以下步骤使用Spring Web Framework开发基于动态表单的W ...
- fabric 自动化部署
fabric 项目发布和运维的工作相当机械,频率还蛮高,导致时间浪费在敲大量重复的命令上. 修复bug什么的,测试,提交版本库(2分钟),ssh到测试环境pull部署(2分钟),rsync到线上机器A ...
- Python Theano ValueError: y_i value out of bounds
参考 https://groups.google.com/forum/#!topic/theano-users/tY3fNAPYd9k 这个问题是由于outs的数量没有设置对. 里面写到 “excep ...
- C++调用Fortran程序----动态链接方式
参考http://yxbwuhee.blog.sohu.com/143577510.html 一.C++动态调用Fortran DLL (1)创建FORTRAN DLL工程,生成forsubs.dll ...
- HDU2602Bone Collector 简单0-1背包
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu1754(splay tree 单点更新,成段查询)
题意就是简单的点更新,成段查询. splay tree 果真是常数比较大的log(n)操作. 比线段树还慢了这么多. // // main.cpp // splay // // Created by ...
- linux下安装nmon监控工具
1.首先下载压缩包 wget http://sourceforge.net/projects/nmon/files/download/nmon_x86_12a.zip/download 2.解压并修改 ...
- JavaSctipt语句for循环的思考
一.语法 for (语句 1; 语句 2; 语句 3) { 被执行的代码块; } 语句 1: 在循环(代码块)开始前执行, 可选. 语句 2: 定义运行循环(代码块)的条件, 可选, 如果省略了语句 ...