题意

给定一个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. LPAT: Learning to Predict Adaptive Threshold for Weakly-supervised Temporal Action Localization [Paper Reading]

    Motivation: 阈值分割的阈值并没有通过模型训练学出来,而是凭借主观经验设置,本文通过与背景得分比较提取对应的proposal,不用阈值的另一篇文章是Shou Zheng的AutoLoc,通过 ...

  2. maven 引入qrcode.jar

        mvn install:install-file -Dfile=e:\QRCode.jar -DgroupId=QRCode -DartifactId=QRCode -Dversion=3.0 ...

  3. 利用TCHART做分离饼形图

    https://www.cnblogs.com/gaodu2003/archive/2009/06/18/1505720.html unit Unit1; interface ……type  TFor ...

  4. Android工具使用之UiAutomatorViewer

    学习博客: https://blog.csdn.net/l403040463/article/details/79235670    使用, 添加web 网页的监控.

  5. vs2012新建单元测试

    多写单元测试也是算向优秀程序员迈进吧((ˇˍˇ)),就像我们小时候做算算术一样,老师会交给我们怎么样检验答案是否正确性.那么我们做程序员也一样,检验自己写的代码是否和我们预期的结果一样!项目小还行,但 ...

  6. 一. jmeter

    1.性能测试概述 1.1 主要方向是测试系统在一定负荷压力下,系统的响应时间,吞吐量,稳定性,系统的可扩展性等性能指标. 结合应用的架构和实现细节找出问题,并最终确认问题得到解决的过程. 目的: 1. ...

  7. 网络编程之TCP三次握手与四次挥手、基于TCP协议的套接字编程

    目录 TCP三次握手和四次挥手 背景描述 常用的熟知端口号 TCP概述 TCP连接的建立(三次握手) TCP四次挥手 如果已建立连接,客户端突然断开,会怎么办呢? 基于TCP协议的套接字编程 什么是S ...

  8. python爬虫---单线程+多任务的异步协程,selenium爬虫模块的使用

    python爬虫---单线程+多任务的异步协程,selenium爬虫模块的使用 一丶单线程+多任务的异步协程 特殊函数 # 如果一个函数的定义被async修饰后,则该函数就是一个特殊的函数 async ...

  9. 2019-08-01 JQuery事件

    Jquery简单的事件 l blur(fn) 当失去焦点时 l change(fn) 当内容发生改变时 l click(fn) 当鼠标单击时 l dblclick 当鼠标双击时 l focus(fn) ...

  10. 基于OpenGL三维软件开发

    实验原理: OpenGL在MFC下编程原理---- Windows操作系统对OpenGL的支持 在Windows下用GDI作图必须通过设备上下文(DeviceContext简写DC)调用相应的函数:用 ...