题目链接 题意 : 给你N,K,M,N可以+,- ,*,% M,然后变为新的N,问你最少几次操作能使(原来的N+1)%K与(新的N)%k相等.并输出相应的操作. 思路 : 首先要注意题中给的%,是要将负数变为正数的,所以取余的时候要注意,又因为各种问题…… % 的问题是:a mod b = (a % b + b) % b,不是平常的取余. 讨论里有个人是这样说的: 关于此题的用bfs搜索,大家都是知道的. 既然使用了bfs,则队列是少不了的,为了叙述的方便,记运算符集合 oper = {+,-,…
题目链接 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) 数字…
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,…
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…
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…
题目链接 题意:4*4的黑白棋,求把棋全变白或者全变黑的最小步数. 分析:以前用状态压缩做过. 和上题差不多,唯一的不同是这个终态是黑棋或者白棋, 但是只需要把给的初态做不同的两次处理就行了. 感觉现在还只是会套模板,不能独立的思考,好伤心.... #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #includ…
One Person Game Time Limit: 2 Seconds      Memory Limit: 65536 KB There is an interesting and simple one person game. Suppose there is a number axis under your feet. You are at point A at first and your aim is point B. There are 6 kinds of operations…
One Person Game Time Limit: 2 Seconds      Memory Limit: 65536 KB There is an interesting and simple one person game. Suppose there is a number axis under your feet. You are at point A at first and your aim is point B. There are 6 kinds of operations…
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18847    Accepted Submission(s): 6090Special Judge Problem Description The Princess has been abducted by the BEelzebub…
题目地址: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,按照正…