题目

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

做法

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

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. Android.mk解析

    https://developer.android.com/ndk/guides/android_mk.html#over LOCAL_STATIC_LIBRARIES PREBUILT_STATIC ...

  2. plsql programming 11 记录类型

    记录类型非常类似数据库表中的行. 记录作为一个整体本身并没有值, 不过每个单独成员或字段都有值, 记录提供了一种把这些值当做一组进行操作的方法. 例如: 1: -- create a table 2: ...

  3. 微信强大的demo

    https://github.com/xialeistudio/wechatPublicPlatform

  4. php 防止刷新重复下载文件

    在超链接中增加随机数. <a href="./index.php?module=operation&action=download&url=D:\WW\WlequPho ...

  5. pip依赖安装与记录

    pip freeze requirements.txt是一个常常被许多Flask应用用于列出它所依赖的包的文本文件.它是通过pip freeze > requirements.txt生成的. 使 ...

  6. jsp a href怎么传参数?

    jsp中超链接传值使用键值对格式,多个键值对之间用&分隔,即<a href="show.jsp?name=tom&pass=123&score=78,5&quo ...

  7. Win7机器上安装Ubuntu 14.0.4

    折腾了两天,分享一下经历. 我须要在已经安装了win7的机器上安装Ubuntu 14.0.4 (两者共存),研究下来有例如以下几种方案, 都折腾了一遍.分享一下经验: 方式1: wubi.exe, 把 ...

  8. Java 基础巩固,根深而叶茂

    #J2SE ##基础 八种基本数据类型的大小,以及他们的封装类. 八种基本数据类型,int ,double ,long ,float, short,byte,character,boolean 对应的 ...

  9. 原生JavaScript写AJAX

    前端JavaScript: function ajaxGet(url, obj) { var request; if(window.XMLHttpRequest) { request = new XM ...

  10. unity坑faq

    遇到的坑记录下来,大都都是听说,没有实测 1. Graphics.copyTexture,在某些机型上不支持从不同类型拷贝 2. msaa 小米mix2不支持,晓龙845 3. android4.2下 ...