亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

第一次參加topcoder的感悟和解題報(bào)告

系統(tǒng) 1983 0

SRMdiv2第三題:

(頭兩題太水,就不貼出來(lái)了. . . . . . )
參照大神的代碼,終于理解(至少我認(rèn)為基本懂了)了:下面是原題,大意是有N本書(shū),給你一個(gè)數(shù)組a,a[n] = m代表的意思是要讀懂第N本書(shū)就必須先讀第m本書(shū),如果m = -1,則不需要讀其他的書(shū)便可讀懂...然后求,:如果隨機(jī)讀這N本書(shū),問(wèn)能夠讀懂的書(shū)的數(shù)目的數(shù)學(xué)期望,
思路:算出每一本書(shū)的期望,加起來(lái)就是總數(shù)目的期望,,,對(duì)于第i本書(shū),總可以找到一條以Si開(kāi)始以Sj結(jié)束有向鏈(其中S(i+1) = a[Si], a[Sj] = -1),,然后在這條鏈中每一本書(shū)跟其他的書(shū)是獨(dú)立的,,也就是說(shuō),,讀不讀其他的書(shū)與這些書(shū)沒(méi)關(guān)系,,,對(duì)于Si,要讀懂它,就得先讀S(i+1)到S(j)這些書(shū),期望為1 / len!,,,,(len是這條鏈的長(zhǎng)度,,,就是排列組合,不多說(shuō)了....)然后迭代這N本書(shū)的期望,,疊加得總數(shù)目期望.......
這是第一次參加Topcoder的比賽:感覺(jué)刷的題太少了,沒(méi)經(jīng)驗(yàn),,,,最大的感悟就是,,,代碼越簡(jiǎn)單越好(當(dāng)然是在正確的前提下).晦澀難懂的代碼自己都懶得看,,,而且還不一定能夠編譯通過(guò)...還有就是在數(shù)據(jù)量很少的情況下優(yōu)秀考慮用暴力法.,,,學(xué)好數(shù)學(xué)很重要!! !還好我是數(shù)學(xué)系的,,<:-:>
下面附上原題和大神的代碼截圖::::
Problem Statement
King Dengklek is the perfect king of Kingdom of Ducks, where slimes and ducks live together in peace and harmony.

Kingdom of Ducks has a pretty strange currency system. There are only two coin types: one with value A and one with value B , where A and B are different. This currency system is denoted by { A , B }. These two coin types are sufficient for daily transactions, because all prices in this kingdom are in the form of ( A *p + B *q) for some non-negative integers p and q. Therefore, slimes and ducks can pay for any goods with a combination of the two coin types.

Bored with the current system, King Dengklek considered another currency system with two coin types: one with value X and one with value Y, where X and Y are different. Of course, with this new system, combinations of the two new coin types must make it possible to pay all the prices one could pay with currency system { A , B }. (Note that the new coin types may also make it possible to pay some additional prices.)

You are given ints A , B , and X . Return the number of different positive integers Y (other than X ) such that the currency system { X , Y} can be used to replace the currency system { A , B }. If there is an infinite number of possible values for Y, return -1 instead.

Definition

Class: KingXNewCurrency
Method: howMany
Parameters: int, int, int
Returns: int
Method signature: int howMany(int A, int B, int X)
(be sure your method is public)

Constraints

- A , B , and X will each be between 1 and 200, inclusive.
- A and B will be different.

Examples

0)
                            5
                          
                            8
                          
                            5
                          
                    Returns: 5
                  
These are the 5 possible currency systems: {5, 1}, {5, 2}, {5, 3}, {5, 4}, and {5, 8}.

圖片

第一次參加topcoder的感悟和解題報(bào)告


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 奇米网久久 | 黑人超长巨大xxxxxxx视频 | 草草在线观看视频 | 亚洲毛片免费视频 | 97综合久久| 久久亚洲成人 | 欧美日片 | 午夜免费福利网站 | 青草91视频免费观看 | 国产一区二区福利久久 | 欧美日韩在线免费观看 | 久久久久久天天夜夜天天 | 久久色亚洲 | 欧美一级aa天码毛片 | 国产首页精品 | 97免费视频免费视频 | 美女超逼 | 色一情一乱一伦麻豆 | 免费视频毛片 | 久久久午夜精品 | 亚洲精品第一国产麻豆 | 亚洲婷婷在线 | 毛片a级放荡的护士hd | 国产成人综合高清在线观看 | 国产毛片一区二区三区精品 | 欧美色欧美亚洲高清在线观看 | 国产香蕉一区二区在线观看 | 亚洲自拍中文 | 欧美日韩国产高清一区二区三区 | 日韩欧美亚洲中字幕在线播放 | 精品日韩在线观看 | 天天摸天天操免费播放小视频 | 成人网18免费视频 | 日本欧美一区二区三区乱码 | 色综合久久综合网欧美综合网 | 欧美日韩不卡视频 | 久久久全国免费视频 | 九九99视频在线观看视频观看 | 精品久久国产视频 | 天天干天天拍天天射 | 国产免费一区二区三区在线观看 |