栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2426 Remainder

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2426 Remainder

#include<iostream>#include<vector>using namespace std;struct point{ int p,n,m; char ch;}list[2000];bool sign[2000];vector<char>end;int n,k,m,n1,h,r;int bfs(){    point temp; h=0; r=1; list[0].n=(n+k*1000)%k; list[0].m=(n+m*1000)%m; list[0].p=0; list[0].ch=0; while(r>h)     {  temp=list[h];  if(temp.n==n1&& h)     return 1;  temp.n=(temp.n+m)%k; //+  if(sign[temp.n]==0)  {   sign[temp.n]=1;   temp.ch='+';   temp.p=h;   list[r++]=temp;  }  temp=list[h];  temp.n=(temp.n-m+k*1000)%k;//-  if(sign[temp.n]==0)  {   sign[temp.n]=1;   temp.ch='-';   temp.p=h;   list[r++]=temp;  }  temp=list[h];  temp.n=(temp.n*m)%k;//*  if(sign[temp.n]==0)  {   sign[temp.n]=1;   temp.ch='*';   temp.m=temp.m*m%m;//娉ㄦ剰杩欏彞,濡傛灉娌℃湁绛変綘涓嬫鎵ц%鏃讹紝灏变細鍑虹幇 (*m%k) %m杩欐牱鐨勯敊璇簡   temp.p=h;   list[r++]=temp;  }  temp=list[h];  temp.n=temp.m%k;//%  if(sign[temp.n]==0)  {   sign[temp.n]=1;   temp.ch='%';   temp.p=h;   list[r++]=temp;  }  ++h; }//while return 0;}int main(){ char s; int i;   while(cin>>n>>k>>m)   {    if(k!=0 && m!=0)    {    memset(sign,0,sizeof(sign));    end.clear();    n1=(n+1+k*1000)%k;    if(bfs())        {     while(h)     {      s=list[h].ch;      end.push_back(s);      h=list[h].p;     }     cout<<end.size()<<endl;     for(i=end.size()-1;i>=0;i--)      cout<<end[i];     cout<<endl;    }    else     cout<<0<<endl;    }    else break;   }   return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/374300.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号