首页 技术 正文
技术 2022年11月12日
0 收藏 480 点赞 4,255 浏览 1843 个字

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,m的公倍数都行))。

还有就是用了vis标记数组,标记过的就不能在标记了。

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1000000000
#define N 2510
#define mod 1000000000
using namespace std; struct point
{
int num;
string a;
}; int n,m,k,mk;
int vis[]; void bfs()
{
memset(vis,,sizeof(vis));
point s;
s.num=n,s.a="";
queue<point>que;
que.push(s);
vis[(n%k+k)%k]=;
while(!que.empty())
{
point e=que.front();que.pop();
if((e.num%k+k)%k==((n+)%k+k)%k)
{
cout<<e.a.length()<<endl;
cout<<e.a<<endl;
return ;
}
s.num=(e.num+m)%mk;
s.a=e.a+'+';
if(!vis[(s.num%k+k)%k])
{
que.push(s);
vis[(s.num%k+k)%k]=;
}
s.num=(e.num-m)%mk;
s.a=e.a+'-';
if(!vis[(s.num%k+k)%k])
{
que.push(s);
vis[(s.num%k+k)%k]=;
}
s.num=(e.num*m)%mk;
s.a=e.a+'*';
if(!vis[(s.num%k+k)%k])
{
que.push(s);
vis[(s.num%k+k)%k]=;
}
s.num=(e.num%m+m)%m%mk;
s.a=e.a+'%';
if(!vis[(s.num%k+k)%k])
{
que.push(s);
vis[(s.num%k+k)%k]=;
}
}
puts("");
}
int main()
{
// freopen("a.txt","r",stdin);
while(~scanf("%d%d%d",&n,&k,&m))
{
if(n==&&m==&&k==) break;
mk=m*k;
bfs();
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,078
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,553
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,402
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,177
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,814
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898