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 acpigs at 2009-04-28 17:58:58 on Problem 2769
程序思路:假设a%m=k,同时b%m=k;易见abs(a-b)%m =0;
本题就是将任两个输入的num相减,则减的结果的因子必然不是本题解,cal函数便是完成此功能,用ID【i】=1表示当前点不可用···还有问题吗?
#include <iostream>
#include <math.h>
const int MAXN = 1000001;
bool ID[MAXN];
int num[300];
int siz;
void solve_one();
int main()
{
    int t;
    scanf("%d",&t);
    while (t--&&scanf("%d",&siz)==1&&siz>=1)
        solve_one();
    return 0;
}
void cal(int x)
{
    int i;
    double c = sqrt(x*1.0)+1;
    for (i=2;i<c;i++)
    {
        if (x%i == 0)ID[i] = 1;
    }
    ID[x] = 1;
}
void solve_one()
{
    memset(ID,0,sizeof(ID));
    int i,j;
    for (i=0;i<siz;i++)
        scanf("%d",num+i);
    for (i=0;i<siz;i++)
        for (j=i+1;j<siz;j++)
            cal (abs(num[i]-num[j]));
    if (siz == 1)
    {
        printf("1\n");
        return;
    }
    for (i=siz;i<MAXN;i++)
        if (ID[i] == 0)/*ID[i] == 1表示可用*/
        {
            printf("%d\n",i);
            return;
        }
}

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