Git Product home page Git Product logo

hw2020's Introduction

2020华为软件精英挑战赛

由于平台太迷弃坑。5分代码。

问题:给一个有向图,问有多少个长度在3-7的简单环。

思路

ID离散化(hh, disc)。

深搜找出距离每个点正走3步以内的点和倒走3步以内的点(dfs3)。

枚举一条边(x, y),满足x < y则枚举$$(b_x(1), f_y(1)), (b_x(1), f_y(2)),(b_x(1), f_y(3)),(b_x(2), f_y(3)),(b_x(3), f_y(3))$$中相同的点z(checksame)。其中$b_a(k)$为a为起点反走有向边k步,$f_a(k)$为a为起点正走有向边k步。

找出所有(z -> x), (y -> z)的路径(getroute),乘法原理组合,同时检查是否满足x为全环最小,环为简单环。如果是,加入结果集合(push_to_res)。

结果集合排序输出。

可优化点

  • 删去不在环上的点
  • listf可以只保留比当前点大的
  • getroute可以提前删去包含过小点的情况,减少枚举
  • listf, listr相关的dfs3, getroute思路优化
  • checksame时,(0,2)(1,1)(2,0)之类的等价,可以选少的check
  • 枚举边按照从小到大,可以省了最后的排序
  • dfs可以换成bfs减少重复
  • 枚举边找环和dfs可以多线程
  • STL代码的优化
  • 输入输出优化
  • 离散化代码优化

hw2020's People

Contributors

zyr17 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.