PersonalCorpus 版 (精华区)

Your C++ program has solved Ok the problem 10025 (The ? 1 ? 2 ? ... ? 
n = k problem)
in 0.010 seconds with low memory spent.

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include <ctype.h>


void main()
{
#ifndef ONLINE_JUDGE
    freopen("c:\\uva\\input10025.txt","r",stdin);
    freopen("c:\\uva\\output10025.txt","w",stdout);
#endif

    int i,j,k,n;

    scanf("%d\n",&n);
    while (n>0) {
        n--;
        scanf("%d\n",&k);
        if (k<0) k=-k;
        for (i=1;;i++) {
            j=i*(i+1)/2;
            if ((j>=k)&&((j-k)%2==0)) break;
        }
        printf("%d\n",i);
        if (n>0) printf("\n");
    }
}


[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.740毫秒