K - Assigning Frequencies

Bob wants to assign frequencies to n satellites, numbered from 0 to n−1. Two distinct satellites are
said to be adjacent if, when assigned the same frequency, they interfere with each other. Sensibly,
Bob’s assignment of frequencies must avoid interference altogether. However, only three frequencies
are available to him.
Please determine whether Bob can assign frequencies to all satellites to avoid any interference.
Technical Specification

  1. There are at most 85 test cases
  2. The number of satellites is n, n ≤ 25.
    Input
    The first line of the input contains an integer indicating the number of input cases.
    For each test case, the first line contains an integer n, denoting the number of satellites. The second
    line contains an integer p, denoting the number of adjacent pairs of satellites. The next p lines each
    contains two integers i, j, indicating the satellite i may intefer with satelite j when both are assigned
    the same frequency.
    Output
    For each test case, output ‘Y’ if Bob can assign frequences so there is no integerence. Output ‘N’
    otherwise.

大体意思就是,给你一个图将这个图用三种颜色染色,要求有边相连的两个点不能是相同的颜色,请问这个图能不能实现
题目先给测试数量,再给点数和边数,下面有边数行,每行两个数,代表这两个点有边相连。注意点是从零开始的(对下面的初始化有影响)

这是一道很典型的dfs的变式题,我们只需要从某个点出发,遍历每个点,尝试给每个点涂上颜色(从第一种颜色开始,遍历与它相连的点,如果与想染的颜色相同则换一种颜色,如果不同则染上,如果三种颜色都不行则失败),当所有点都染色上颜色时就成功了。

#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int a[10100];//频率
int mp[1010][1010];//
int dfs(int step,int n)
{for(int i=0; i<step; i++){if(mp[i][step]==1&&a[i]==a[step])//相邻结点相同频率return 0;}if(step==n-1)//遍历结束return 1;for(int i=0; i<3 ; i++)//三种颜色{a[step+1]=i;//选颜色if(dfs(step+1,n)==1)return 1;}return 0;
}
int main()
{int t;cin>>t;while(t--){int n,m;memset(a,0,sizeof(a));memset(mp,0,sizeof(mp));cin>>n>>m;while(m--){int u,v;cin>>u>>v;mp[u][v]=mp[v][u]=1;//标记相邻}if(dfs(0,n)==1)printf("Y\n");elseprintf("N\n");}return 0;
}

K - Assigning Frequencies相关推荐

  1. Slope one—个性化推荐中最简洁的协同过滤算法

    Slope One 是一系列应用于 协同过滤的算法的统称.由 Daniel Lemire和Anna Maclachlan于2005年发表的论文中提出. [1]有争议的是,该算法堪称基于项目评价的non ...

  2. 面向程序员的数据挖掘指南-----第三章:隐式评价和基于物品的过滤算法

    本章会从用户的评价类型开始讨论,包括显式评价(赞一下.踩一脚.五星评价等等)和隐式评价(比如在亚马逊上购买了MP3,我们可以认为他喜欢这个产品). 内容: 显式评价 隐式评价 哪种评价方式更准确? 基 ...

  3. GB_T28181-2016.pdf

    国标28181-2016版本检测,由于文件过大,而且博客不支持上传文件,需要GB28181-2016协议文档和公安一所检测文档的可以私信我,QQ:123011785 I C S1 3. 3 1 0 A ...

  4. 使用python简单实现K核苷酸频率(KNF,k-nucleotide frequencies)或K-mer频率

    K核苷酸频率(KNF,k-nucleotide frequencies)或K-mer频率 KNF描述了序列中存在k个核苷酸的所有可能的多核苷酸的频率.如果k=2,则计算的为双核苷酸频率(即AA.AT. ...

  5. knn 邻居数量k的选取_选择K个最近的邻居

    knn 邻居数量k的选取 Classification is more-or-less just a matter of figuring out to what available group so ...

  6. Longest Substring With At Most K Distinct Characters

    Given a string, find the length of the longest substring T that contains at most k distinct characte ...

  7. perl 哈希数组的哈希_第一个元素使用哈希在数组中出现K次

    perl 哈希数组的哈希 Prerequisite: Hashing data structure 先决条件: 哈希数据结构 Problem statement: 问题陈述: Find the fir ...

  8. k均值聚类的python代码_k-均值聚类Python代码实现

    这里给出两种方式的k-均值实现,code主要来自于网络: # reference: https://mubaris.com/2017/10/01/kmeans-clustering-in-python ...

  9. Codeforces Round #766 (Div. 2)C. Not Assigning

    C. Not Assigning 题意:给出n个节点,n-1条路经,给每条路径赋上初值(这里的值必须为素数),使得每两条路径权值之和为素数,且对于每条路径,每个节点只能访问一次(即判断是否为线性结构) ...

最新文章

  1. r语言中正定矩阵由于误差不正定_Kalman滤波在MOT中的应用(一)——理论篇
  2. mysql 指定日期条件求和_如何在mysql中按每个日期对字段进行求和-问答-阿里云开发者社区-阿里云...
  3. 一种快速的公交专用车道检测方法
  4. autoresetevent java_[原创]AutoResetEvent, ManualResetEvent的Java模拟
  5. java fx border_JavaFx UI控件与代码间的绑定方法
  6. NET 下数据库图片的存入与读取
  7. PostgreSQL数据库 OLTP高并发请求性能优化
  8. 顺通车间扫码出入库管理系统仓库扫码软件
  9. Polar Si9000如何选择模型计算射频线宽?
  10. 正交匹配追踪算法OMP
  11. java后台对接app微信支付
  12. stata 导出 相关系数表_【BBtime】戏说会计论文---stata简单实操
  13. [转]关于Gmail打不开的解决办法
  14. 解决 ERROR oslo_service.periodic_task AttributeError: ‘ComputeNode‘ object has no attribute ‘nodename‘
  15. 读书:《人人都是产品经理》-苏杰
  16. 解决WPS每点击一下保存,就会出现tmp文件
  17. deepin做服务器稳定吗,deepin从兴致勃勃到彻底放弃
  18. 微信开发者工具预览二维码无法显示
  19. ESIM模型的“全能版”!网易易盾实验室研究员解读HIM混合推理模型
  20. C# Xamarin For Android移动开发项目实战篇

热门文章

  1. 信息精准智能推送(push)的五个关键
  2. 搜狗输入法——导入本地txt词库
  3. Ol3中Map事件全解析
  4. Scratch幻影小猫 电子学会图形化编程scratch等级考试三级真题答案2019-9
  5. it培训和自学的优缺点分析
  6. 关于Android短信拦截(二)
  7. linux环境查看cpu是否开启睿频
  8. 微信小程序用户信息解
  9. C语言基础知识复习(1)
  10. CAN总线通信原理分析