UVa10025 ? 1 ? 2 ? ... ? n = k problem The problem Given the following formula, one can set operators '+' or '-' instead of each '?', in order to obta ...
分类:
其他好文 时间:
2017-04-13 00:45:12
阅读次数:
164
分析:因为数字之间只有加减变换,所以-k和k是一样的,都可以当成整数来考虑,只要找到最小的n满足sum=n*(n+1)/2>=k;且sum和k同奇同偶即可,做法是用二分查找,然后在就近查找因为1,2,3,4,5,6……的sum变化是奇奇偶偶奇奇偶偶奇奇偶偶……程序: 1 import java.ma...
分类:
其他好文 时间:
2015-08-12 18:57:39
阅读次数:
97
10025 The ? 1 ? 2 ? … ? n = k problem
Given the following formula, one can set operators ‘+’ or ‘-’ instead of each ‘?’, in order to obtain a given k ?1?2?…?n = k
For example: to obtain k = 12, the e...
分类:
其他好文 时间:
2015-07-06 14:21:12
阅读次数:
118