hdu 1104 数论+bfs】的更多相关文章

Remainder Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2122    Accepted Submission(s): 449 Problem Description Coco is a clever boy, who is good at mathematics. However, he is puzzled by a d…
http://acm.hdu.edu.cn/showproblem.php?pid=1104 注意这里定义的取模运算和计算机的%是不一样的,这里的取模只会得到非负数. 而%可以得到正数和负数. 所以需要 a mod b = (a % b + b) % b 这样转换得到. 并且,由于新的N可以很大,所以我们每一步都要取%,而且最后要mod k,正常来说每步都%k就行了,但是由于其中的一个操作是N%m,所以我们每一步就不能%k了(%k%m混用会导致%出来的答案错误),而要%(k *m)(其实%(k,…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1104 在做这道题目一定要对同余定理有足够的了解,所以对这道题目对同余定理进行总结 首先要明白计算机里的取余计算和数学里的不一样的,计算机里的负数取余可以是负数的.例如-1%11=-1 而数学里的取余是-1%11=10 同余定理: 若a对d取余,和b对d取余的结果是相等的,那么称a,b对d是同余的.记作a≡b(mod d);这是数学里的定义. 下面看同余定理的几个性质: 1,a≡a(mod d) 数字…
Remainder Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2260 Accepted Submission(s): 481 Problem Description Coco is a clever boy, who is good at mathematics. However, he is puzzled by a difficu…
GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD. \[ x=(p_1^{i_1})*(p_2^{i_2})*(p_3^{i_3})\dots \] \[ y=(p_1^{j_1})*(p_2^{j_2})*(p_3^{j_3})\dots \] \[ z=(p_1^{k_1})*(p_2^{k_2})*(p_3^{k_3})\dots \] \…
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1104 题意:给你一个n.m.k,有四种操作n+m,n-m,n*m,n%m,问你最少经过多少步,使得最后的结果=(初始n+1)%k 题解:很明显的BFS,然后我就很快写,果断RE,发现里面可能有负数,改了之后还是错了,看了discuss才发现原来要%mk,现在还是不是很懂为什么,这里discuss有人给出了解释—— 解释一下为什么要%mk: 对于N来说,其中的过程会有N+m,N-m,以及N*m,按照正…
Remainder Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3036    Accepted Submission(s): 679 Problem Description Coco is a clever boy, who is good at mathematics. However, he is puzzled by a d…
Remainder Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2255 Accepted Submission(s): 479 Problem Description Coco is a clever boy, who is good at mathematics. However, he is puzzled by a difficu…
题目链接 题意 : 给你N,K,M,N可以+,- ,*,% M,然后变为新的N,问你最少几次操作能使(原来的N+1)%K与(新的N)%k相等.并输出相应的操作. 思路 : 首先要注意题中给的%,是要将负数变为正数的,所以取余的时候要注意,又因为各种问题…… % 的问题是:a mod b = (a % b + b) % b,不是平常的取余. 讨论里有个人是这样说的: 关于此题的用bfs搜索,大家都是知道的. 既然使用了bfs,则队列是少不了的,为了叙述的方便,记运算符集合 oper = {+,-,…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4528 小明系列故事——捉迷藏 Time Limit: 500/200 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1464    Accepted Submission(s): 423 Problem Description 小明的妈妈生了三个孩子,老大叫大明, 老二叫…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1072 Description Ignatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The labyrinth has an exit, Ignatius should get out of the labyrinth before the bomb explodes.…
http://acm.hdu.edu.cn/showproblem.php?pid=3533 一道普通的bfs,但是由于代码实现出了bug还是拖了很久甚至对拍了 需要注意的是: 1.人不能经过炮台 2.能量耗尽时如果进入终点且终点没有炮弹也可以 3.炮台会遮挡住别的炮弹 前两点认为读题时不能确定 #include <cstdio> #include <cstring> #include <algorithm> #include <queue> using n…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2389 思路:纯裸的一个最大匹配题,不过悲摧的是以前一直用的dfs版一直过不了,TLE无数次啊,然后改成bfs就过了. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<cmath> #inc…
http://acm.hdu.edu.cn/showproblem.php?pid=1495 题目就不说了, 说说思路! 倒可乐 无非有6种情况: 1. S 向 M 倒 2. S 向 N 倒 3. N 向 M 倒 4. N 向 S 倒 5. M 向 S 倒 6. M 向 N 倒 根据上述的六种情况来进行模拟, 每次模拟的结果都放进队列里面. 注意: 还要用到标记数组,防止数据重复进入队列导致爆栈. #include<stdio.h> #include<stdlib.h> #incl…
题目链接:hdu 4856 Tunnels 题目大意:给定一张图,图上有M个管道,管道给定入口和出口,单向,如今有人想要体验下这M个管道,问最短须要移动的距离,起点未定. 解题思路:首先用bfs处理出两两管道之间移动的距离,然后后用状态压缩求出最短代价,dp[i][j],i表示的已经走过的管道,j是当前所在的管道. #include <cstdio> #include <cstring> #include <queue> #include <algorithm&g…
题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison. Angel's friends want to save Angel. Their task…
题目大意:中文题不说了. 题目思路:我有同学用GCD数论写出来的代码很简洁,但是很抱歉,数论蒟蒻,我觉得比赛的时候我没办法推出.如果用BFS的话思路很简单的,就是6方向广搜,只不过稍微麻烦点.具体看代码吧. #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<iostream> #define M…
思路: 这三个题是一个比一个令人纠结呀. POJ-1077 爆搜可以过,94ms,注意不能用map就是了. #include<iostream> #include<stack> #include<queue> #include<map> #include<cstring> using namespace std; ; const int inf = 2.1e9; ; ; ; ][]; int Head[maxn]; int viss[maxn];…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison…
http://acm.hdu.edu.cn/showproblem.php?pid=1495 题意: 有3个杯子a b c:a=b+c:然后刚开始时只有a是满的,其它为空的,然后a b c三个之间互相倒,假如说a倒入b中,只有当b满或a空时,才算倒一次: a=4,b=1;c=3; 因为刚开始只有a中有: 先让a倒入c中3:step++; c倒入b中1:step++; b倒入a中1:step++;此时a和c中各有2: 代码如下: #include<iostream> #include<st…
http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <queue> #include <vector> #include <i…
Snacks 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5692 Description 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充,零食机的价值v会时常发生变化.小度熊只能从编号为0的零食机出发,并且每个零食机至多经过一次.另外,小度熊会对某个零食机的零食有所偏爱,要求路线上必须有那个零食机. 为小度熊规划一个路线,使得路线上的价值总和最大.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3085 思路:双向广搜,每次从M出发,搜三步,从G出发,搜一步,然后就是判断是否走到对方已经走过的格子,至于魔王的判断,可以用曼哈顿距离. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace s…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241 Oil Deposits Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13137    Accepted Submission(s): 7611 Problem Description The GeoSurvComp geologi…
Different Digits Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1430    Accepted Submission(s): 392 Problem Description Given a positive integer n, your task is to find a positive integer m, w…
http://acm.hdu.edu.cn/showproblem.php?pid=1072 遇到Bomb-Reset-Equipment的时候除了时间恢复之外,必须把这个点做标记不能再走,不然可能造成死循环,也得不到最优解. #include <cstdio> #include <cstring> #include <queue> using namespace std; struct point { int x,y,time,step; }; point s; in…
题目:这里 题意: 相当于一开始给一个初始好了的无向完全图给你,然后给让你删除m条边,再给你一个点v,最后问你在剩下的图里从这个点v出发能到达所有边点的最小路径是多少? 一看是所有点的最小路径,一看就觉得是个bfs,记忆化搜一下然后加个优化什么的,由于数据不知道是个什么奇葩而且比赛中还改数据,所以很多人wa的莫名其妙, 过也过的莫名其妙,我虽然过了但觉得有点不靠谱,赛后看了https://async.icpc-camp.org/d/546-2016的题解思路写了一发,总感觉更靠谱一点. 之前自己…
Gap Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 690    Accepted Submission(s): 380 Problem Description Let's play a card game called Gap.  You have 28 cards labeled with two-digit numbers…
http://acm.hdu.edu.cn/showproblem.php?pid=1548 Online Judge Online Exercise Online Teaching Online Contests Exercise Author F.A.QHand In HandOnline Acmers Forum |DiscussStatistical Charts Problem ArchiveRealtime Judge StatusAuthors Ranklist       C/C…
E - charge-station Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4435 Appoint description: Description There are n cities in M^3's empire. M^3 owns a palace and a car and the palace resides in…