ZOJ-Crashing Balloon

先從最大的數開始, 深度優先遍歷.?

如果是 m 和 n 的公因子, 先遍歷m的, 回溯返回的數值還是公因子, 再遍歷n.

如果有某一或幾條路徑可以讓 m 和 n 變成 1 ,說明 m 和 n 不沖突, m 勝利.

如果沒有找到一條路徑當 n 分解完成時, m 也分解完成, 則判定 m說謊(無論 n 是否說謊), n 勝利.

 1 #include <iostream>
 2 using namespace std;
 3 bool flagM, flagN;
 4 void dfs(int m, int n, int factor){
 5     //cout << "M N:" << m <<" "<< n << endl;
 6     if (m == 1 && n == 1){//兩個都被完全因式分解
 7         //cout << flagM << flagN << endl;
 8         flagM = flagN = true;
 9         return;
10     }
11     if (n == 1)//小數被分解完,大數還未被分解完 
12         flagN = true;
13     while (factor>1){
14         
15         if (m%factor == 0) {
16             //cout <<"FLAG:" << flagM << flagN << endl;
17             dfs(m / factor, n, factor - 1);
18         }
19         
20         if (n%factor == 0) {
21             cout << flagM << flagN << endl;
22             dfs(m, n / factor, factor - 1);
23         }
24         factor--;
25         //cout << "FACTOR:" <<factor << endl;
26     }
27 }
28 int main(){
29     int m, n;
30     while (cin>>m>>n){
31         if (m<n){
32             int t = m;
33             m = n;
34             n = t;
35         }
36         flagM = flagN = false;
37         dfs(m, n, 100);
38         if (!flagM && flagN)
39             cout << n << endl;
40         else
41             cout << m << endl;
42     }
43     return 0;
44 }

?

轉載于:https://www.cnblogs.com/miyamochio/p/9675866.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388475.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388475.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388475.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

使用TensorFlow概率預測航空乘客人數

TensorFlow Probability uses structural time series models to conduct time series forecasting. In particular, this library allows for a “scenario analysis” form of modelling — whereby various forecasts regarding the future are made.TensorFlow概率使用結構…

python畫激活函數圖像

導入必要的庫 import math import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl mpl.rcParams[axes.unicode_minus] False 繪制softmax函數圖像 fig plt.figure(figsize(6,4)) ax fig.add_subplot(111) x np.linspace(-10,10) y sigmoid(x)ax.s…

計算機網絡管理SIMP,計算機網絡管理實驗報告.docx

計算機網絡管理實驗報告計算機網絡管理實驗報告PAGEPAGE #計算機網絡管理實驗報告作 者&#xff1a; 孫玉虎 學 號&#xff1a;914106840229學院(系)&#xff1a;計算機科學與工程學院專 業&#xff1a;網絡工程題 目&#xff1a;SNMR報文禾口 MIB指導教師陸一飛2016年12月目錄…

tomcat集群

1】 下載安裝 httpd-2.2.15-win32-x86-no_ssl.msi 網頁服務器 32-bit Windows zip tomcat mod_jk-1.2.30-httpd-2.2.3.so Apache/IIS 用來連接后臺Tomcat的模塊&#xff0c;支持集群和負載均衡 JK 分為兩個版本 1,x 和 2.x &…

pdf.js插件使用記錄,在線打開pdf

pdf.js插件使用記錄&#xff0c;在線打開pdf 原文:pdf.js插件使用記錄&#xff0c;在線打開pdf天記錄一個js庫&#xff1a;pdf.js。主要是實現在線打開pdf功能。因為項目需求需要能在線查看pdf文檔&#xff0c;所以就研究了一下這個控件。 有些人很好奇&#xff0c;在線打開pdf…

程序員 sql面試_非程序員SQL使用指南

程序員 sql面試Today, the word of the moment is DATA, this little combination of 4 letters is transforming how all companies and their employees work, but most people don’t really know how data behaves or how to access it and they also think that this is j…

Apache+Tomcat集群負載均衡的兩種session處理方式

session共享有兩種方式&#xff1a; 1、session共享&#xff0c;多個服務器session拷貝保存&#xff0c;一臺宕機不會影響用戶的登錄狀態&#xff1b; 2、請求精確集中定位&#xff0c;即當前用戶的請求都集中定位到一臺服務器中&#xff0c;這樣單臺服務器保存了用戶的sessi…

SmartSVN:File has inconsistent newlines

用SmartSVN提交文件的時候&#xff0c;提示svn: File has inconsistent newlines 這是由于要提交的文件編碼時混合了windows和unix符號導致的。 解決方案 SmartSVN設置做如下修改可以解決問題&#xff1a; Project–>Setting選擇Working copy下的EOL-style將Default EOL-sty…

我要認真學Git了 - Config

有一天&#xff0c;當我像往常一樣打開SourceTree提交代碼&#xff0c;然后推送的時候&#xff0c;我突然意識到我只是根據肌肉記憶完成這個過程&#xff0c;我壓根不知道這其中到底發生了什么。這是個很嚴重的問題&#xff0c;作為一個技術人員&#xff0c;居然只滿足于使用工…

計算機科學與技術科研論文,計算機科學與技術學院2007年度科研論文一覽表

1Qiang Sun,Xianwen Zeng, Raihan Ur Rasool, Zongwu Ke, Niansheng Chen. The Capacity of Wireless Ad Hoc Networks with Power Control. IWCLD 2007. (EI收錄: 083511480101)2Hong jia ping. The Application of the AES in the Bootloader of AVR Microcontroller. In: DC…

r a/b 測試_R中的A / B測試

r a/b 測試什么是A / B測試&#xff1f; (What is A/B Testing?) A/B testing is a method used to test whether the response rate is different for two variants of the same feature. For instance, you may want to test whether a specific change to your website lik…

一臺機器同時運行兩個Tomcat

如果不加任何修改&#xff0c;在一臺服務器上同時運行兩個Tomcat服務顯然會發生端口沖突。假設現在已經按照正常的方式安裝配置好了第一個Tomcat,第二個如何設置呢&#xff1f;以下是使用Tomcat5.5解壓版本所做的實驗。 解決辦法&#xff1a; 1.解壓Tomcat到一個新的目錄&#…

PHP獲取IP地址的方法,防止偽造IP地址注入攻擊

PHP獲取IP地址的方法,防止偽造IP地址注入攻擊 原文:PHP獲取IP地址的方法,防止偽造IP地址注入攻擊PHP獲取IP地址的方法 /*** 獲取客戶端IP地址* <br />來源&#xff1a;ThinkPHP* <br />"X-FORWARDED-FOR" 是代理服務器通過 HTTP Headers 提供的客戶端IP。…

工作10年厭倦寫代碼_厭倦了數據質量討論?

工作10年厭倦寫代碼I have been in tons of meetings where data and results of any sort of analysis have been presented. And most meetings have one thing in common, data quality is being challenged and most of the meeting time is used for discussing potential…

Java基礎回顧

內容&#xff1a; 1、Java中的數據類型 2、引用類型的使用 3、IO流及讀寫文件 4、對象的內存圖 5、this的作用及本質 6、匿名對象 1、Java中的數據類型 Java中的數據類型有如下兩種&#xff1a; 基本數據類型: 4類8種 byte(1) boolean(1) short(2) char(2) int(4) float(4) l…

oracle數據庫 日志滿了

1、 數據庫不能啟動SQL> startupORACLE 例程已經啟動。Total System Global Area 289406976 bytesFixed Size 1248576 bytesVariable Size 83886784 bytesDatabase Buffers 197132288 bytesRedo Buffers 7139328 byt…

計算機應用基礎學生自查報告,計算機應用基礎(專科).docx

1.在資源管理器中&#xff0c;如果要選擇連續多個文件或文件夾&#xff0c;需要單擊第一個文件或文件夾&#xff0c;按下鍵盤()&#xff0c;再用鼠標單擊最后一個文件或文件夾即可。(A)Shift(B)Tab(C)Alt(D)Ctrl分值&#xff1a;2完全正確?得分&#xff1a;2?2.下列數據能被E…

Random隨機數

Random 隨機數 1 產生隨機數 1.1 Random的使用步驟 我們想產生1-100(包含1和100)的隨機數該怎么辦&#xff1f;我們不需要自己寫算法&#xff0c;因為額Java已經為我們提供好了產生隨機數的類---Random 作用&#xff1a;用于產生一個隨機數 使用步驟(和Scanner類似)&#xff1a…

模擬一個簡單計算器_閱讀模擬器的簡單介紹

模擬一個簡單計算器Read simulators are widely being used within the research community to create synthetic and mock datasets for analysis. In this article, I will introduce some recently proposed, commonly used read simulators.閱讀模擬器在研究社區中被廣泛使…

計算機部分應用顯示模糊,win10系統打開部分軟件字體總顯示模糊的解決方法-電腦自學網...

win10系統打開部分軟件字體總顯示模糊的解決方法。方法一&#xff1a;win10軟件字體模糊1、首先&#xff0c;在Win10的桌面點擊鼠標右鍵&#xff0c;選擇“顯示設置”。2、在“顯示設置”的界面下方&#xff0c;點擊“高級顯示設置”。3、在“高級顯示設置”的界面中&#xff0…