D. Shortest Cycle

A[i]&A[j]!=0连边,

求图中最小环

N>128 时必有3环

其他暴力跑

folyd最小环

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define sc(x) scanf("%I64d",&x);
  5. #define read(A) for(int i=0;i<n;i++) scanf("%I64d",&A[i]);
  6. ll A[];
  7. ll B[][];
  8. ll dis[][];
  9. ll N;
  10. #define inf 1e18
  11. ll floyd()
  12. {
  13. ll MinCost = inf;
  14. for(int k=; k<=N; k++)
  15. {
  16. for(int i=; i<k; i++)
  17. for(int j=i+; j<k; j++)
  18. MinCost = min(MinCost,dis[i][j]+B[i][k]+B[k][j]);
  19. for(int i=; i<=N; i++)
  20. for(int j=; j<=N; j++)
  21. dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
  22. }
  23. if(MinCost==inf)return -;
  24. else return MinCost;
  25. }
  26.  
  27. int main()
  28. {
  29. // ll N;
  30. sc(N);
  31. ll _k=;
  32. for(int i=; i<=N; i++)
  33. {
  34. sc(A[_k]);
  35. if(A[_k]!=)_k++;
  36. }
  37. if(_k>=)
  38. {
  39. puts("");
  40. }
  41.  
  42. else
  43. {
  44. N=_k-;
  45. for(int i=; i<=N; i++)
  46. {
  47. for(int j=; j<=N; j++)
  48. {
  49. if(i!=j&&(A[i]&A[j]))
  50. {
  51. B[i][j]=;
  52. dis[i][j]=;
  53. }
  54. else if(i==j)
  55. {
  56. B[i][j]=;
  57. dis[i][j]=;
  58. }
  59. else
  60. {
  61. B[i][j]=inf;
  62. dis[i][j]=inf;
  63. }
  64. }
  65. }
  66. cout<<floyd()<<'\n';
  67.  
  68. }
  69.  
  70. }

D. Shortest Cycle的更多相关文章

  1. CF 1206D - Shortest Cycle Floyd求最小环

    Shortest Cycle 题意 有n(n <= 100000)个数字,两个数字间取&运算结果大于0的话连一条边.问图中的最小环. 思路 可以发现当非0数的个数很大,比如大于200时, ...

  2. Codeforces 1206 D - Shortest Cycle

    D - Shortest Cycle 思路:n大于某个值肯定有个三元环,否则floyd找最小环. 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) ...

  3. D. Shortest Cycle(floyd最小环)

    D. Shortest Cycle time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. [Codeforces 1205B]Shortest Cycle(最小环)

    [Codeforces 1205B]Shortest Cycle(最小环) 题面 给出n个正整数\(a_i\),若\(a_i \& a_j \neq 0\),则连边\((i,j)\)(注意i- ...

  5. Codeforces Round #580 (Div. 2)-D. Shortest Cycle(思维建图+dfs找最小环)

    You are given nn integer numbers a1,a2,…,ana1,a2,…,an. Consider graph on nn nodes, in which nodes ii ...

  6. 并不对劲的复健训练-CF1205B Shortest Cycle

    题目大意 有\(n\)(\(n\leq 10^5\))个数\(a_1,...,a_n\)(\(a\leq 10^{18}\)).有一个图用这个方法生成:若\(a_i\)按位与\(a_j\)不为0,则在 ...

  7. 【题解】Shortest Cycle

    原题链接:CF1205B   题目大意   给定\(n\)个整数\(a_1,a_2,a_3, \dots ,a_n\),若\(i \neq j\)且\(a_i \land a_j \neq 0\),则 ...

  8. [CF580C]Shortest Cycle(图论,最小环)

    Description: 给 \(n\) 个点的图,点有点权 \(a_i\) ,两点之间有边当且仅当 \(a_i\ \text{and}\ a_j \not= 0\),边权为1,求最小环. Solut ...

  9. @codeforces - 1205B@ Shortest Cycle

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 n 的正整数序列 a1, a2, ..., an ...

随机推荐

  1. 无法在发送 HTTP 标头之后进行重定向

    public ActionResult Index2() { Response.Buffer = true; Response.Clear(); return Redirect("/Wech ...

  2. Double类型的数值 在写入excel时 如何去掉 科学计算法的 后面数值+ E的 情况

    Double start = 20190724100000.000; 写入excel时 是 201907E+13 但想要输出的是 20190724100000 这种格式 Java在java.math包 ...

  3. linux rz上传-sz下载

    yum install lrzsz -y rz     上传文件    不能传目录 如果要传目录需要打包成文件再上传 需要往哪里传东西,先进入哪个目录 rz -y   上传覆盖 sz -y 文件名  ...

  4. python学习之路 目录

    python Python基础-1 python由来 字符编码 注释 pyc文件 python变量 导入模块 获取用户输入 流程控制if while python基础-2 编码转换 pycharm 配 ...

  5. 配置NAT

    NAT是将IP数据报文报头中的IP地址转换为另-一个IP地址的过程,主要用于实现内部网络(私有IP地址)访问外部网络(公有IP地址)的功能.NAT有3种类型:静态NAT.动态地址NAT以及网络地址端口 ...

  6. P1074 靶形数独 dfs+预处理

    https://www.luogu.org/problemnew/show/P1074 显然是dfs 而且没有什么剪枝记忆化之类的 但是预处理比较麻烦 我用三个二维数组存状态:visx[x][i]代表 ...

  7. uboot第二阶段分析1

    一. uboot第二阶段初识 1.1. uboot第二阶段应该做什么 a. 概括来讲uboot第一阶段主要就是初始化了SoC内部的一些部件(譬如看门狗.时钟),然后初始化DDR并且完成重定位. b.  ...

  8. pureftp安装

    1.下载 #cd /usr/local/src #wget http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.36.t ...

  9. C# List<Object>值拷贝

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Run ...

  10. 06.Linux系统-GitLab版本控制服务安装部署

    官方文档:https://about.gitlab.com/install/#centos-7 1.yum install -y curl policycoreutils-python openssh ...