sicily 1218. 纪念邮票

来源:互联网 发布:怎么在淘宝上买电影票 编辑:程序博客网 时间:2024/06/15 10:14

http://soj.sysu.edu.cn/show_problem.php?pid=1218

之前大概做了下居然做对了。。然后化简了下。。只要注意长度为偶数时左边L的值要+1

#include <cstdio>#include <cmath>int main(){    int n,m;    scanf("%d%d",&n,&m);    int len = sqrt(2*m)+1;    while(--len)    {        int l = m/len-len/2+!(len&1);        int r = m/len+len/2;        if(l < 1 || r > n) continue;        if((l+r)*(r-l+1)/2 == m)            printf("[%d,%d]\n",l,r);    }}                                 

0 0
原创粉丝点击