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

poj 1078 Gizilch

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

poj 1078 Gizilch

#include <iostream>#include <string.h>#define MAXV(a, b) ((a) >= (b) ? (a) : (b))#define MINV(a, b) ((a) <= (b) ? (a) : (b))#define MAX_N 100using namespace std; int high, low;bool visited, found; bool used[MAX_N + 5];bool getRes(int pos, int low, int high) {    //如果能进这个IF语句,则说明当前所求数是可以分解为100以内不重复的因子的    if(low == 1)     {        //如果小的数的因子分解已经完成,那么说明当前进行的是较大数的因子分解,则说明这两套因子是不相交的        if(visited)  return true;         else         { //进行标记, visited为true说明较小数的因子分解已经完成 found = visited = true; //对较大数进行因子分解 if(getRes(1, high, high)) return true;  visited = false;  return false;         }     }    //因子超出了范围    else if(pos > 100)         return false;     else     {        //DFS所有的分解方案        for(int i = pos; i <= 100; i++)         {  if(low % i == 0 && !used[i])  {     //对已经使用过的因子进行分解     used[i] = true;     //DFS下一步     if(getRes(pos + 1, low / i, high))          return true;      used[i] = false;  }         }         return false;     } }int main() {     int temp1, temp2;     while(cin>>temp1>>temp2)     {         high = MAXV(temp1, temp2);         low = MINV(temp1, temp2);        visited = found = false;         memset(used, 0, sizeof(used));         bool res = getRes(1, low, high);         if(res) cout<<high<<endl;         else         {  if(found)      cout<<low<<endl;  else      cout<<high<<endl;         }      }      return 0; }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372954.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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