分析:非常像货车运输那道题.先求一下最大生成树.求完之后会发现并不好处理.通常这类求生成树的题目不会就分析kruscal算法的性质.每往最大生成树中加一条边,如果配重大于这条边权,那么这条边所连的两个集合就都要建一个仓库.也可以这么想:本来在所有点都建仓库,如果配重小于这条边的边权,那么少建一个仓库.把所有的边权放进一个数组里,排个序,二分一下就好了.

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n,m,q,fa[],p[],cnt;
struct node
{
int u,v,w;
}e[]; bool cmp(node a,node b)
{
return a.w > b.w;
} int find(int x)
{
if (x == fa[x])
return x;
return fa[x] = find(fa[x]);
} bool cmp2(int x,int y)
{
return x > y;
} int main()
{
scanf("%d%d%d",&n,&m,&q);
for (int i = ; i <= n; i++)
fa[i] = i;
for (int i = ; i <= m; i++)
scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
sort(e + ,e + + m,cmp);
for (int i = ; i <= m; i++)
{
int fu = find(e[i].u),fv = find(e[i].v);
if (fu != fv)
{
fa[fu] = fv;
p[++cnt] = e[i].w;
}
}
sort(p + ,p + + cnt,cmp2);
while (q--)
{
int temp;
scanf("%d",&temp);
int l = ,r = cnt,ans = ;
while (l <= r)
{
int mid = (l + r) >> ;
if (p[mid] >= temp)
{
ans = mid;
l = mid + ;
}
else
r = mid - ;
}
printf("%d\n",n - ans);
} return ;
}

noip模拟赛 仓库的更多相关文章

  1. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  2. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  3. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  4. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

  5. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

  6. 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...

  7. 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...

  8. CH Round #58 - OrzCC杯noip模拟赛day2

    A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...

  9. CH Round #52 - Thinking Bear #1 (NOIP模拟赛)

    A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...

随机推荐

  1. js中实现json格式的转换

    function person(id,name,age){ this.id=id; this.name=name; this.age=age; } var p=new person(1001,'tom ...

  2. Linux普通到root用户切换-转

    1.Linux中的用户切换:su和su - 的区别 大部分Linux发行版的默认账户是普通用户,而更改系统文件或者执行某些命令,需要root身份才能进行,这就需要从当前用户切换到root用户,Linu ...

  3. HTML5 File API的应用

    HTML5 File API简介 HTML5File API协议族 Directories and System   文件系统和目录读取 FileWriter   写入文件 FileReader   ...

  4. jdk线程池,使用手记

    Executors----------------------------------------------Executors------------------------------------ ...

  5. poj3109 Inner Vertices

    思路: 树状数组 + 扫描线. 实现: #include <cstdio> #include <vector> #include <algorithm> using ...

  6. 使用Kotlin,抛弃findViewById

    有没有觉得Android的findViewById挺烦人的.使用Kotlin可以让你彻底抛弃这个烦恼 步骤1.在build.gradle(Module:app)中添加如下一句话 这个在老一点版本的An ...

  7. object -c OOP , 源码组织 ,Foundation 框架 详解1

     object -c  OOP ,  源码组织  ,Foundation 框架 详解1 1.1 So what is OOP? OOP is a way of constructing softwar ...

  8. AIX上安装oracle10g

    AIX上安装oracle10g: 建议将oracle软件装在本地磁盘,数据文件放在共享存储上 安装数据库需提前规划的工作: DBCA 创建数据库时,如果勾了EM选项,则会检测监听. 首先rootpre ...

  9. cookie和session的用法用途,执行流程,区别联系

    1.为什么要有cookie/session?在客户端浏览器向服务器发送请求,服务器做出响应之后,二者便会断开连接(一次会话结束).那么下次用户再来请求服务器,服务器没有任何办法去识别此用户是谁.比如w ...

  10. http 1.0 http 1.1 http 2.0的区别

    HTTP/1.0 版的主要缺点是,每个TCP连接只能发送一个请求.发送数据完毕,连接就关闭,如果还要请求其他资源,就必须再新建一个连接. http1.1优点: 1.HTTP 1.1 版引入了持久连接( ...