ACM一道算法题,我的算法为何WADescription There is N pairs of balls in a small box.That means the number for each pair is the same.However,for some reason,a ball is lost.Now,you will get the number of the rest.Can you find the number of the

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/05 11:32:43
ACM一道算法题,我的算法为何WADescription There is N pairs of balls in a small box.That means the number for each pair is the same.However,for some reason,a ball is lost.Now,you will get the number of the rest.Can you find the number of the

ACM一道算法题,我的算法为何WADescription There is N pairs of balls in a small box.That means the number for each pair is the same.However,for some reason,a ball is lost.Now,you will get the number of the rest.Can you find the number of the
ACM一道算法题,我的算法为何WA
Description
There is N pairs of balls in a small box.That means the number for each pair is the same.However,for some reason,a ball is lost.Now,you will get the number of the rest.Can you find the number of the lost ball as fast as possible?
Input
The input consists of several test cases.For each case,the first line contains an integer N(1

ACM一道算法题,我的算法为何WADescription There is N pairs of balls in a small box.That means the number for each pair is the same.However,for some reason,a ball is lost.Now,you will get the number of the rest.Can you find the number of the
楼主的算法应该是没有问题的,问题可能出在具体的实现上,因为没有代码,也不好推断问题所在.
刚才实现了楼主的算法,结果也是WA.
遂又尝试了一下二叉排序树法,依然WA……
然后呢,我把两种方法都进行了下改进,设置了检查条件,如果有超过一个不成对的数字出现,就进入死循环,结果是,两种算法都会超时.
所以,说一下我的猜测(对,是猜测,因为我不能完全保证我的算法实现了我的想法,也就不能证明我的推测是正确的),那就是,测试数据并不像题目描述那样,除一个数字之外,其余全部两两成对.
异或的算法确实能保证在数据如题目描述的情况下求得正确答案,但它在数据错误时也能得出一个解,并且无法检查数据的正确性.
所以,我再进行一个大胆的猜想,这道题目的数据制作者,是假定了这样一种算法为正确解法,然后呢,用了某种不能保证符合题目描述的方法生成了测试数据,再用这种算法得到了参考答案,却没有用其它算法进行验证……
通过观察这道题的统计数据,我猜大概绝大多数的人都是用这种算法通过的.
再次重申,以上猜测未经严格验证.楼主如果有兴趣,也可以自己试一下:)

ACM一道算法题,我的算法为何WADescription There is N pairs of balls in a small box.That means the number for each pair is the same.However,for some reason,a ball is lost.Now,you will get the number of the rest.Can you find the number of the 提供几道Dijkstra算法的ACM水题练习 acm程序设计的都有什么算法 一道算法题,算法好或者搞ACM的童鞋看过来~题目在这里:首先说这道题目不是很难,但是我自己想了一个算法,我认为挺对的,使用的例子都能得到正确答案,但是怎么都通不过去,我知道标准的话 关于算法与数据结构的一道题 acm竞赛的算法总共有那些范围?求大牛概括. 杭电acm 2035 题的算法是怎样的,杭电acm 2035 题的算法是怎样的,我要算法分析,不要代码!Problem Description求A^B的最后三位数表示的整数.说明:A^B的含义是“A的B次方”Input输入数据包含多个测试实 请教一道极限算法的问题,我这哪错了? 一道关于等比数列的题,哪个知道简便的算法,帮帮我吧.谢谢、、、、 什么叫acm程序设计与算法分析 算法 算法 求一道数学分析算法题目的程序 一道ACM编程题 求算法思路.给出一些无序的数比如5 3 4 2 1每次可以交换其中任意2个数现在求最少的交换次数 使序列变得从小到大有序怎么求最小的交换次数呢?说下思路就行了希望算法够快 求个C语言一道算法题的算法ABCDEFG每个人对应1234567号 他们每个人都拿不到自己号码的情况 这个算法该是怎样 有谁能不能给想一个用数据结构中排序或者图形中算法的一个变形算法?也就是帮忙用排序或图形出一道算法题 图论,算法推荐几本图论的书,想参加ACM竞赛. acm算法书籍求推荐 除了白书 还有什么详细讲解数据结构的?