ZOJ1003 Crashing Balloon

來源:互聯網
上載者:User

雖說是深搜,但是自己的代碼總是wa。。。

上網看了一些代碼,基本上都是同一個樣子

膜拜ing。。。


/******************************************************************************* # Author : Neo Fung # Email : neosfung@gmail.com # Last modified: 2012-04-07 20:29 # Filename: ZOJ1003 Crashing Balloon.cpp # Description :  ******************************************************************************/#ifdef _MSC_VER#define DEBUG#define _CRT_SECURE_NO_DEPRECATE#endif#include <fstream>#include <stdio.h>#include <iostream>#include <string.h>#include <string>#include <limits.h>#include <algorithm>#include <math.h>#include <numeric>#include <functional>#include <ctype.h>#define MAX 101using namespace std;int flag1,flag2;  void dfs(int x,int y,int n)  {    if(y==1)    {       flag2=1;      if(x==1)flag1=1; //先分解較小數,所以較大數被分解(就是flag1置1)的條件是較小數已經被分解    }    if(n>100 || flag1==1 && flag2==1) return;//遞迴出口:n超過100,或者兩個數都被分解    if(x%n==0) dfs(x/n,y,n+1);  //大的數用因子n  if(y%n==0) dfs(x,y/n,n+1);  //小的數用因子n  dfs(x,y,n+1);               //都不用因子n}  int main(void){#ifdef DEBUG    freopen("../stdin.txt","r",stdin);  freopen("../stdout.txt","w",stdout); #endif    int a,b,t;    while(~scanf("%d%d",&a,&b))    {      if(a<b){t=a;a=b;b=t;} //確保a>b      flag1=flag2=0;      dfs(a,b,2);           //從2開始搜尋      //printf("%d %d/n",flag1,flag2);      if(flag2&&!flag1)printf("%d\n",b);//挑戰成功只有一種情況,就是較小數分解成功,大數失敗      else printf("%d\n",a);    }    return 0; }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.