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 Leon_Xu at 2010-10-29 20:52:12 on Problem 1006
#include <stdio.h>

int main(int argc, char* argv[])
{
    int p=0, e=0, i=0, d=0;
    int px=0, ex=0, ix=0;
    int n=0, m=0;

    int results[5000];

    for(n=0;;n++)
    {
        results[n] = 0;

        scanf("%d %d %d %d", &p, &e, &i, &d);

        if(p==-1 && e==-1 && i==-1 && d==-1)
            break;

        px = p % 23;
        ex = e % 28;
        ix = i % 33;

        p = (28*33)%23;
        for(m=0;(p*m)%23!=px;m++);
        results[n] += 28*33*m;

        e = (23*33)%28;
        for(m=0;(e*m)%28!=ex;m++);
        results[n] += 23*33*m;

        i = (23*28)%33;
        for(m=0;(i*m)%33!=ix;m++);
        results[n] += 23*28*m;

        results[n] %= 21252;
        results[n] = results[n] > d ? results[n]-d : results[n]+21252-d;
    }

    for(m=0; m<n; m++)
        printf("Case %d: the next triple peak occurs in %d days.\n"
            , m+1, results[m]);

    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