2017icpc beijing-I题-Colored Nodes
题意
给定一个n个点m条边的无向图,一开始点i的颜色为i,在第i+kn秒开始时,与节点i相邻的节点会被染成i的颜色(k为自然数)
定义D(i,j)第j秒结束时颜色为i的节点个数,求: $F(i)=\lim_{n -> \infty }{1\over n}\sum_{j=1}^{n}D(i,j)$
题解
代码
#include<bits/stdc++.h>
using namespace std; const int maxn = + ;
struct Edge{
int next, to;
}edges[*maxn];
int head[maxn], id; void add(int u, int v)
{
edges[id].to = v;
edges[id].next = head[u];
head[u] = id++;
} int n, m;
int ans[maxn];
int color[maxn];
bool vis[maxn];
int kind[maxn], color_num[maxn]; bool cmp(int x, int y)
{
return x > y;
} int main()
{
while(scanf("%d%d", &n, &m) == )
{
id = ;
//memset(head, -1, sizeof(head));
for(int i = ;i <= n;i++)
{
head[i] = -;
vis[i] = ;
color_num[i] = ;
ans[i] = ;
kind[i] = ;
color[i] = i;
}
//for(int i = 1;i <=n;i++) color[i] = i;
//memset(vis, 0, sizeof(vis));
//memset(color_num, 0, sizeof(color_num));
//memset(ans,0,sizeof(ans));
//memset(kind, 0, sizeof(kind));
for(int i = ;i < m;i++)
{
int a, b;
scanf("%d%d", &a, &b);
add(a, b);
add(b, a);
}
for(int i = ;i <= n;i++)
for(int j = head[i];j != -;j = edges[j].next)
{
int v = edges[j].to;
color[v] = color[i];
} for(int i = ;i <= n;i++)
vis[color[i]] = true; //哪些颜色出现过 int cnt = ;
for(int i = ;i <= n;i++)
if(vis[i]) kind[cnt++] = i; //第cnt种颜色为i for(int i = ;i <= n;i++)
color_num[color[i]]++; //for(int i = 1;i <= n;i++) printf("%d\n", kind[i]); for(int i = ;i <= n;i++)
{
for(int j = head[i];j != -;j = edges[j].next)
{
int v = edges[j].to;
color_num[color[v]]--; //把与i相连的颜色减去1
color[v] = color[i];
color_num[color[i]]++;
}
for(int j = ;j < cnt;j++) //对于每种颜色
ans[kind[j]] += color_num[kind[j]];
}
//sort(ans+1, ans+n+1, cmp);
for(int i = ;i <= n;i++)
{
if(ans[i]) printf("%.6f\n", ans[i]*1.0/n);
//else break;
}
}
return ;
}
参考链接:
1. https://blog.csdn.net/qq_37699336/article/details/83244519
2017icpc beijing-I题-Colored Nodes的更多相关文章
- 乘风破浪:LeetCode真题_025_Reverse Nodes in k-Group
乘风破浪:LeetCode真题_025_Reverse Nodes in k-Group 一.前言 将一个链表按照一定的长度切成几部分,然后每部分进行翻转以后再拼接成一个链表是比较困难的,但是这也能锻 ...
- 乘风破浪:LeetCode真题_024_Swap Nodes in Pairs
乘风破浪:LeetCode真题_024_Swap Nodes in Pairs 一.前言 这次还是链表的操作,不过我们需要交换链表奇数和偶数位置上的节点,因此要怎么做呢? 二.Swap Nodes i ...
- leetcode第24题--Reverse Nodes in k-Group
problem: Given a linked list, reverse the nodes of a linked list k at a time and return its modified ...
- leetcode第23题--Swap Nodes in Pairs
Problem: Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1 ...
- 2017ICPC南宁 M题 The Maximum Unreachable Node Set【二分图】
题意: 找出不能相互访问的点集的集合的元素数量. 思路: 偏序集最长反链裸题. 代码: #include<iostream> #include<cstring> using n ...
- 2017icpc乌鲁木齐网络赛Colored Graph (构造)
题目 https://nanti.jisuanke.com/t/16958 题意 给定一个n(n<=500)个点的无向图,给每条边黑白染色,输出同色三角形最少的个数和对应的方案 分析 首先考虑给 ...
- 2017ICPC南宁补题
https://www.cnblogs.com/2462478392Lee/p/11650548.html https://www.cnblogs.com/2462478392Lee/p/116501 ...
- HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)
Destroying the bus stations ...
- Leetcode中单链表题总结
以下是个人对所做过的LeetCode题中有关链表类型题的总结,博主小白啊,若有错误的地方,请留言指出,谢谢. 一.有关反转链表 反转链表是在单链表题中占很大的比例,有时候,会以各种形式出现在题中,是比 ...
随机推荐
- BZOJ3145 [Feyat cup 1.5]Str 后缀树、启发式合并
传送门--BZOJCH 考虑两种情况: 1.答案由一个最长公共子串+可能的一个模糊匹配位置组成.这个用SAM求一下最长公共子串,但是需要注意只出现在\(S\)的开头和\(T\)的结尾的子串是不能够通过 ...
- Redis高级功能-1、高并发基本概述
1.可能的问题 要将redis运用到工程项目中,只使用一台redis是万万不能的,原因如下: (1)从结构上,单个redis服务器会发生单点故障,并且一台服务器需要处理所有的请求负载,压力较大. (2 ...
- https相关知识总结
从园子里看到很多讲解不错的文章,将链接放到这里,备忘 浅析数字证书:https://www.cnblogs.com/hyddd/archive/2009/01/07/1371292.html
- JAVA中List,Map,Set接口的区别
从三点来分析它们之间的不同: 1.继承的接口不同: List,Set接口都是继承于Collection接口的,而Map接口不是,它是一个顶层接口. 2.自身特点: List:用来处理序列的.对于放于的 ...
- HeRaNO's NOIP CSP Round Day 2 T1 building
考试的时候居然睡着了... T1的60分做法很明显,3^n枚举每个状态并进行验证 (考试剩十分钟结束的时候我开始打,,不到五分钟就写完了? 暴力(60分) #include<bits/stdc+ ...
- 2019-07-30 ThinkPHP文件上传
文件上传就是获取到待上传文件的临时路径,把它移动到服务器下的相应文件夹中. 文件上传,必须在表单中的form标签中写入:enctype="multipart/form-data" ...
- Fiddler抓本机包
使用Fiddler抓本机包的方法: File -->Capture Traffic 选中之后自动设置本机的Internet代理选项.
- Spring 开发之组件赋值
1. @Value & @PropertySource 1.1 使用方式 @PropertySource:读取外部配置文件中的 k/v 保存到运行的环境变量中;加载完外部的配置文件以后使用 $ ...
- kbmmw 中的Boyer-Moore算法
kbmmw 5.10 版本中实现了一个非常好用的字符串搜索算法,即Boyer-Moore算法. 在用于查找子字符串的算法当中,BM(Boyer-Moore)算法是目前被认为最高效的字符串搜索算法, 它 ...
- HBase的部署与其它相关组件(Hive和Phoenix)的集成
HBase的部署与其它相关组件(Hive和Phoenix)的集成 一.HBase部署 1.1.Zookeeper正常部署 首先保证Zookeeper集群的正常部署,并启动之: /opt/module/ ...