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题中有关链表类型题的总结,博主小白啊,若有错误的地方,请留言指出,谢谢. 一.有关反转链表 反转链表是在单链表题中占很大的比例,有时候,会以各种形式出现在题中,是比 ...
随机推荐
- [转帖]/var/log/wtmp文件的作用
/var/log/wtmp文件的作用 https://blog.51cto.com/oldyunwei/1658778 /var/log/wtmp是一个二进制文件,记录每个用户的登录次数和持续时间 ...
- Python格式化输出——format用法示例
format OR % 提到Python中的格式化输出方法,一般来说有以下两种方式: print('hello %s' % 'world') # hello world print('hello {} ...
- drf--认证组件
目录 认证简介 用户认证RBAC(Role-Based Access Control) 局部使用 全局使用 源码分析 认证简介 使用场景:有些接口在进行访问时,需要确认用户是否已经登录,比如:用户需要 ...
- tomcat添加https服务
系统环境: centos6.7 jdk-7u79-linux-x64 apache-tomcat-7.0.57 apr-1.5.2 apr-util-1.5.4 一.tomcat安装 自己准备tomc ...
- vue使用html2canvas生成图片并保存到本地
html2canvas官方文档 http://html2canvas.hertzen.com/ npm下载依赖 npm install html2canvas -S 在需要使用的地方引入 import ...
- hadoop中HDFS的NameNode原理
1. hadoop中HDFS的NameNode原理 1.1. 组成 包括HDFS(分布式文件系统),YARN(分布式资源调度系统),MapReduce(分布式计算系统),等等. 1.2. HDFS架构 ...
- consul:kv
consul除了提供了服务发现的功能,还是提供了kv store的功能,kv store可用于动态配置服务.协调服务.leader选举等场景. consul的kv提供了cli和http的两种接口: h ...
- JS 正则表达式转换字符串
获取第一个.前面的字符串,以及后面的字符串: const transform = str => { str.replace(/([^\.]*)\.(.*)/, function($0, $1,$ ...
- 使用代码获得Hybris Commerce里显示的产品图片
使用下面这个API去取Hybris Commerce系统里产品主数据的明细信息: https://:9002/rest/v2/electronics/products/300938?fields=FU ...
- Executor的线程代码
package com.open1111; import java.util.concurrent.ExecutorService;import java.util.concurrent.Execut ...