SRMdiv2第三题:
(头两题太水,就不贴出来了. . . . . . )
参照大神的代码,终于理解(至少我认为基本懂了)了:下面是原题,大意是有N本书,给你一个数组a,a[n] = m代表的意思是要读懂第N本书就必须先读第m本书,如果m = -1,则不需要读其他的书便可读懂...然后求,:如果随机读这N本书,问能够读懂的书的数目的数学期望,
思路:算出每一本书的期望,加起来就是总数目的期望,,,对于第i本书,总可以找到一条以Si开始以Sj结束有向链(其中S(i+1) = a[Si], a[Sj] = -1),,然后在这条链中每一本书跟其他的书是独立的,,也就是说,,读不读其他的书与这些书没关系,,,对于Si,要读懂它,就得先读S(i+1)到S(j)这些书,期望为1 / len!,,,,(len是这条链的长度,,,就是排列组合,不多说了....)然后迭代这N本书的期望,,叠加得总数目期望.......
这是第一次参加Topcoder的比赛:感觉刷的题太少了,没经验,,,,最大的感悟就是,,,代码越简单越好(当然是在正确的前提下).晦涩难懂的代码自己都懒得看,,,而且还不一定能够编译通过...还有就是在数据量很少的情况下优秀考虑用暴力法.,,,学好数学很重要!! !还好我是数学系的,,<:-:>
下面附上原题和大神的代码截图::::
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 valueAand one with valueB, whereAandBare 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 valueXand one with value Y, whereXand 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 intsA,B, andX. Return the number of different positive integers Y (other thanX) 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. |
相关推荐
Topcoder软件比赛注册方法和平台使用 Topcoder算法大赛客户端安装流程 Topcoder算法大赛客户端登陆及使用 Topcoder算法大赛注册流程 Topcoder图形比赛注册方法和平台使用
适合topcoder新手
给新手提供的TopCoder注册方法和平台使用 十分详细
topcoder竞赛的算法讲座ppt
你可以通过这道题去了解Topcoder的题目以及比赛形式
TopCoder比赛登录使用的客户端,需要配置Java环境
TopCoder新手入门指南,一步步操作既可以了,然后开启您的Topcoder编程之旅吧。
Topcoder的Java客户端,安装前确定已经安装了JRE
用于topcoder的第3方编辑器插件。
topcoder arena,包含ContestAppletProd.jnlp,CodeProcessor.jar,FileEdit.jar,TZTester,运行需要jre环境
TopCoper SmartWordToy problem 解决方法,C++源码。 Problem Statement The toy company "I Can't Believe It Works!...Form: http://community.topcoder.com/stat?c=problem_statement&pm=3935&rd=6532
topcoder的比赛作品,编译通过的。可以放心使用。
topcoder入门,对想做tc,但又不知道怎么搞的很有帮助,我首先也不知道搞。
这是一类关于acm学习的资料,它详细的说明了Acm学习的内容,如何提高编写软件的能力
topcoder的在线答题系统
希望玩玩ACM的人可以下载来看看,TOPCODER上好玩的不少,TOPCODER入门资料
关于TopCoder的竞赛指导,不仅仅是SRM,还有Bug Race、软件比赛的资料,是我从网上收集的,大部分是中文的
关于TopCoder的一些程序竞赛的相关资料
无描述,下载的请自重 无描述,下载的请自重 无描述,下载的请自重 无描述,下载的请自重