题意

给定一个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)$

题解

首先模拟一轮染色过程,求出一轮下来,每个点最终会被染成开始时哪个点的颜色。这个染色结果是一个满射。将这个映射迭代无数次,就相当于染色无数轮。由于映射是满射,迭代的过程中,每个点的颜色会形成一个循环。求出这个循环,就知道每轮结束时每个点的颜色循环情况。最后再模拟一次染色过程,就能求出每个点在每个时刻的颜色循环情况。这样就能求出每个颜色的分数解,转成小数输出即可。

代码

看网上的代码,并不能AC
#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

2. https://www.zhihu.com/question/68280066

3. https://blog.csdn.net/alan_cty/article/details/78713865

 

2017icpc beijing-I题-Colored Nodes的更多相关文章

  1. 乘风破浪:LeetCode真题_025_Reverse Nodes in k-Group

    乘风破浪:LeetCode真题_025_Reverse Nodes in k-Group 一.前言 将一个链表按照一定的长度切成几部分,然后每部分进行翻转以后再拼接成一个链表是比较困难的,但是这也能锻 ...

  2. 乘风破浪:LeetCode真题_024_Swap Nodes in Pairs

    乘风破浪:LeetCode真题_024_Swap Nodes in Pairs 一.前言 这次还是链表的操作,不过我们需要交换链表奇数和偶数位置上的节点,因此要怎么做呢? 二.Swap Nodes i ...

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

  4. leetcode第23题--Swap Nodes in Pairs

    Problem: Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1 ...

  5. 2017ICPC南宁 M题 The Maximum Unreachable Node Set【二分图】

    题意: 找出不能相互访问的点集的集合的元素数量. 思路: 偏序集最长反链裸题. 代码: #include<iostream> #include<cstring> using n ...

  6. 2017icpc乌鲁木齐网络赛Colored Graph (构造)

    题目 https://nanti.jisuanke.com/t/16958 题意 给定一个n(n<=500)个点的无向图,给每条边黑白染色,输出同色三角形最少的个数和对应的方案 分析 首先考虑给 ...

  7. 2017ICPC南宁补题

    https://www.cnblogs.com/2462478392Lee/p/11650548.html https://www.cnblogs.com/2462478392Lee/p/116501 ...

  8. HDUOJ----2485 Destroying the bus stations(2008北京现场赛A题)

    Destroying the bus stations                                                                          ...

  9. Leetcode中单链表题总结

    以下是个人对所做过的LeetCode题中有关链表类型题的总结,博主小白啊,若有错误的地方,请留言指出,谢谢. 一.有关反转链表 反转链表是在单链表题中占很大的比例,有时候,会以各种形式出现在题中,是比 ...

随机推荐

  1. Baidu UEditor .net 下修改默认上传路径

    public override void Process() { byte[] uploadFileBytes = null; string uploadFileName = null; if (Up ...

  2. ElasticSearch 线程池类型分析之 ExecutorScalingQueue

    ElasticSearch 线程池类型分析之 ExecutorScalingQueue 在ElasticSearch 线程池类型分析之SizeBlockingQueue这篇文章中分析了ES的fixed ...

  3. Redis Desktop Manager 0.9.3 版本下载

    因为Redis Desktop Manager作者在 0.9.4 版本之后选择对所有的安装包收费,不再提供安装包下载,但是源码依旧公开.链接:https://pan.baidu.com/s/1SXsy ...

  4. Java学习: 面向对象的使用与注意事项

    面向对象的使用与注意事项 面向过程:当需要实现一个功能的时候,每一个具体的步骤都需要亲力,详细处理每一个细节面向对象:当需要实现一个功能的时候,不关心具体的步骤,而是找一个已经具有该功能的人,来帮我做 ...

  5. Mysql系列(六)—— MySQL索引介绍

    前言 索引种类 索引维护 如何使用索引 一.索引索引种类 MySQL中索引主要包含以下几种: 普通索引 唯一索引 主键索引 联合索引 全文索引 二.索引维护 在简述了索引的类型后,再来了解下如何维护索 ...

  6. 使用git svn clone迁移svn仓库(保留提交记录)

    使用git svn clone迁移svn仓库 clone命令可以指定很多参数,主要用到这些,你也可以使用git svn help查看完整的参数列表. git svn clone https://172 ...

  7. Python开发【第十五篇】模块的导入

    的导入语句 import 语句 语法: import 模块名1 [as 模块别名] 作用: 将某模块整体导入到当前模块 示例: import math import sys,os 用法: 模块名.属性 ...

  8. Jmeter websocket插件安装与使用

    Jmeter websocket插件安装与使用 Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测试,但后来扩展到其他测试 ...

  9. .net core web api 默认的模型验证

    转载自 https://www.codercto.com/a/45938.html

  10. Windows 10 下 GCC / LLVM 的安装和使用

    win10下gcc的安装和makehttps://www.jianshu.com/p/46824c62dfed 方案1:直接官方下载安装minGw或Cygwininstall download: ht ...