题目

对于当年来说似乎是神题??

做法

对于联通注水来说,我们考虑把所有能平分到水的桶同时加高度,然后暴力判断

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]蜘蛛难题的更多相关文章

  1. BZOJ1092 : [SCOI2003]蜘蛛难题

    按时间一步一步模拟. 每一次,首先将所有没有水但是可以被灌到水的管子标记为有水,然后求出有水的管子里水面高度的最小值. 如果$a$号管有水且最小值为$b$,那么说明此时蜘蛛碰到了水. 如果有管子溢出且 ...

  2. 【SCOI2003】【BZOJ1092】蜘蛛难题

    有一堆管道,还有一个蜘蛛Willy,如下图所示.所有管道的是上端开口,下端封底,直径都是1cm,连接两个管道的连接容量无限,但体积可以忽略不计. 在第一个管道上方有一个水源,从中有水不断往下流,速度为 ...

  3. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  4. 探讨webapp的SEO难题(上)

    前言 网络蜘蛛无法解析javascript,至少百度是不能的,神马搜索差的更远,而我们的webapp的渲染展示完全由javascript驱动 所以蜘蛛访问webapp页面会得到一个白页面,比如,我们期 ...

  5. c#蜘蛛

    C#写一个采集器 using System; using System.Collections.Generic; using System.Text; using System.Net; using ...

  6. 深入super,看Python如何解决钻石继承难题 【转】

    原文地址 http://www.cnblogs.com/testview/p/4651198.html 1.   Python的继承以及调用父类成员 python子类调用父类成员有2种方法,分别是普通 ...

  7. 判断来防ip是否为蜘蛛

    判断网站来防IP是否为蜘蛛,用命令查询 :     一.在windows平台 蜘蛛反查命令:nslookup IP 点击"开始"-"运行"-"cmd& ...

  8. 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 ...

  9. 一起来做webgame,《Javascript蜘蛛纸牌》

    不得不说,做游戏是会上瘾的,这次带来的是win系统上的经典游戏<蜘蛛纸牌>,不能完美,但求一玩 移牌 0 次 Javascript game_蜘蛛纸牌 正在努力加载... // " ...

随机推荐

  1. important——》sql server 2000安装图解

    MS Sql Server 2000包含两个部分:服务器组件和客户端工具,其中服务器组建是以Windows服务的方式运行的,有四种服务分别是:MSSqlServer.Distributed Trans ...

  2. Unity3D学习笔记——NGUI之UIInput

    UIInput:这个组件可以用于创建输入框和编辑文本. 效果图如下: 一:使用步骤 1.首先创建一个背景,可以用Sprite也可以是Widget. 我这里使用的是空白的Widget 2.为其添加一个L ...

  3. AndroidManifest.xml详细分析

    原文地址: http://my.eoe.cn/1087692/archive/5927.html 一.关于AndroidManifest.xmlAndroidManifest.xml 是每个andro ...

  4. c++通过类名动态创建对象

    转载:http://www.seacha.com/article.php/knowledge/cbase/2013/0615/2154.html 主要思想:在每次创建类的过程中,通过各自类的辅助类(所 ...

  5. day12闭包,装饰器

    一.闭包:内部函数引用了外部函数的变量. # f1() #闭包的定义 #内部的函数引用了外部函数的变量 # def f1(b): #闭包的常用状态 # def f2(): # print(b) # r ...

  6. Django项目部署(django+guncorn+virtualenv+nginx)

    一.说明 为了django项目部署到生产环境上,能够稳定的运行,且能够同时指出http和https的访问,对django的部署进行了一些研究,决定采用django + gunicorn + virtu ...

  7. float 的先后顺序 理解流

    <!DOCTYPE html><html><head><style> p{float:right;}</style></head> ...

  8. 机器重启 查看crontab执行历史记录crontab没有执行

    Sep 17 19:01:01 d run-parts(/etc/cron.hourly)[8452]: finished 0anacronSep 17 19:10:01 d CROND[9059]: ...

  9. java集合的部分接口

    接口 Collection<E> public interface Collection<E>extends Iterable<E> Collection 层次结构 ...

  10. Python3.6全栈开发实例[012]

    12.输出商品列表,用户输入序号,显示用户选中的商品(升级题) 商品列表: goods = [{"name": "电脑", "price": ...