Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我开始比你还暴力,后来改进的 可是还是超时,都优化了一晚上

Posted by jauhell at 2010-05-13 00:57:00 on Problem 1012
In Reply To:头次碰到超内存。贴个代码,用链表做的。各位大牛有什么方法能改进吗 Posted by:BGW991111 at 2010-03-19 15:10:48
#include <stdio.h>

int main()
{
    int K, temp, n, j, flag;
    long m;
    while(1)
    {
        scanf("%d",&K);
        if(!K)  return 0;
        for(m=2*K-1;;m++)
        {
            temp=2*K;
            n=0;
            flag=0;
            j=(m-1)%(temp);
            while(1)
            {
                if(j<K) break;
                else
                {
                    temp--;
                    n++;
                    j=(j-1+m)%temp;
                    if(n>=K)
                    {
                        printf("%ld\n",m);
                        flag=1;
                        break;
                    }  
                }
            }
            if(flag) break;   
        }
    } 
    return 0;   
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator