Colin's blog

A football fan,an English lover and a coder


  • 首页

  • 分类

  • 关于

  • 归档

  • 标签

Prime Ring Problem

发表于 2016-06-27   |   分类于 acm
原题:hdoj 1016 原题大意如图,6个数收尾相连,任意两个相邻的数之和是质数.现在请你输入数字n,表示从1到n的整数,将它们排列成一个环,形成如图所示的质数环. 算法分析用dfs遍历每种情况 代码程序程序1#include <stdio.h> #include <math.h> #include <memory.h> #define N 20 int a[N],b[N]; int n; int c=0; int is_prime(int t)//判断是否是质数 { int i; if(t==1) return 0; for(i=2;i<=sqrt(t);i++) { if(t%i==0) return 0; } return 1; } int check(int t,int m)//检查有没有与之前的数重复 { int i; for(i=0;i<m;i++) if(t==b[i]) re ...
阅读全文 »

Knight Moves

发表于 2016-06-26   |   分类于 acm
原题:hdoj 1372 算法分析本题有个算法的实现bfs,dfs,Floyd都可以. dfs 用深搜的话就是向8个方向递归,计算从起点到终点的最短距离. bfs 广搜也是向8个方向搜索,不过是把值都放进队列里,这样避免重复搜. Floyd 这是解决表格问题最常用的算法,将棋盘上任意两点的距离全都保存起来,对所有的输入直接查表. 程序代码dfs#include <stdio.h> #include <memory.h> int knight[8][8];//棋盘 int x[]={-1,1,2,2,1,-1,-2,-2};//八个方向 int y[]={2,2,1,-1,-2,-2,-1,1}; void DFS(int si,int sj,int moves) { if(si<0||sj<0||si>=8||sj>=8||moves>=knight[si][sj]) return ; knight[si][sj]=moves; int i; for(i=0;i<8;i++) ...
阅读全文 »

Alien Security

发表于 2016-06-26   |   分类于 acm
原题Language:Alien SecurityTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2898 Accepted: 1064Description You are in charge of security at a top-secret government research facility. Recently your government has captured a live extra-terrestrial (ET) life form, and is hosting an open day for fellow researchers. Of course, not all the guests can be trusted, so they are assigned different security clearance levels. Only guests with a level 5 rating will be allowed into the lab ...
阅读全文 »

Channel Allocation

发表于 2016-06-24   |   分类于 acm
原题Description When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver has a strong signal. However, the channels used by each repeater must be carefully chosen so that nearby repeaters do not interfere with one another. This condition is satisfied if adjacent repeaters use different channels. Since the radio frequency spectrum is a precious resource, the number of channels required by a given network of repeaters should be ...
阅读全文 »

Code the tree

发表于 2016-06-20   |   分类于 acm
DescriptionA tree (i.e. a connected graph without cycles) with vertices numbered by the integers 1, 2, …, n is given. The “Prufer” code of such a tree is built as follows: the leaf (a vertex that is incident to only one edge) with the minimal number is taken. This leaf, together with its incident edge is removed from the graph, while the number of the vertex that was adjacent to the leaf is written down. In the obtained graph, this procedure is repeated, until there is only one vertex left (whic ...
阅读全文 »
1…212223
Shen Hao

Shen Hao

Colin's blog | acm |c++

114 日志
6 分类
71 标签
GitHub
© 2017 Shen Hao
由 Hexo 强力驱动
主题 - NexT.Muse