首页 > 编程知识 正文

霍夫投票算法讲解,多数投票算法

时间:2023-05-06 16:29:30 阅读:168085 作者:2001

主题投票(Voting)

时间限制: C/C 2秒,其他语言4秒空间限制: C/C 262144K,其他语言524288K64bit IO Format: %lld主题描述牛和优秀万宝路在竞争技术组领队,同事们进行了无记名投票活动。

牛有特殊的能力,可以在投票中n次偷看投票结果。 第I次偷看牛牛的话,可以知道现在他的票数和优秀的万宝路的票数之比是n : m,但是他不能知道正确的票数。

n次偷看结束后,牛想知道在满足所有偷看结果比的基础上,现在他和优秀的万宝路得到的票数之和最小是多少吗?

悲伤的孩子andbobareengagedinacompetitionfortechgroupleader,forwhichallcolleaguesarevotingbetweenthem。

Given that悲伤的孩子isabletoseethevotingresultsforntimes.atthei-th time,sheistoknowthevotesshehasgotagainstbob’sinaratiofn 30

After seeing N times,giventhatalltheratiossheseesarecorrect,悲伤丸子wantstoknowtheminimalamountofvotesthatsumsupbothersandbob’

输入描述:

输入包含N 1行。

第一行是正整数n(1n1000 )

接着n行,每行两个正整数m,n(m,n1000 ),保证两个数互相质量。

input contains mathit N 1N 1 lines。

the1 stlineisapositiveintegern (1n1000 )

Then N lines follow,eachlinecontainingtwopositiveintegersn,m

itisensuredthatgcd(n_I,m_i )==1gCD ) Ni,mi )==1。

输出描述:

输出可能的最小票数之和,以确保答案不超过10^18。

outputtheminimalamountofvotesthatsumsupboth悲伤的小丸子’sand bob’s,itisensuredthattheanswerdoesnotexceed 10 ^ 18。

示例1

输入副本32 31 13 2输出副本10说明票数的变化可能为(2,3 )、3 )、3 )、6、4 ),因此最终的最小票数之和为10。 thechangeofamountofvotescanbe : (2,3 ) )、3 )、4 )、so the answer is 10.示例2

输入41 11 11 51 100输出101示例3

53输入53 1048 1731 199231 233 2输出6930码实现分析:每次求出x的最小值minX、y的最小值minY。

如果(x=minX y=minY ),直接代入minX=x; minY=y; 否则,求最大比例math.ceil (() double ) 1.0 * minX )/x ),math.ceil ) ) double ) 1.0 * minY )/y ),如果有小数的话与x、y都相乘求出的最大倍数。 minX,minY. import java.util.Scanner; public class main { publicstaticvoidmain (string [ ] args ) scannerin=newscanner ) system.in; int n=in.nextInt (; 长整型=0; 长miny=0; for(intI=0; i n; I () { int x=in.nextInt ); int y=in.nextInt (; //writeyourcodeif(x=minxy=miny ) ) { minX=x; minY=y; } else { double mulX=1; 双精度=1; if(x0 ) mulx=math.ceil () ) ) double ) 1.0 * minX )/x ); (if ) y0 ) muly=math.ceil ) ) ) double ) 1.0 * minY )/y ); (longmulmax=) long ) math.max ) mulY,mulY ); minx=math.max(minx,x * mulMax ); miny=math.max(miny,y * mulMax ); } } long result=minX minY; system.out.print(result; }是问题吗? 以上所示的Case全部通过,但有些Case没有过去,完全不知道问题在哪里。 也不提供Case。 有人知道问题在哪里。 请在评论中指出。 谢谢

见https://AC.now coder.com/ACM/contest/3286/b

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。