Hdu 1025 - Constructing Roads In JGShining's Kingdom

用二分查找,不知为何一直RE,数组明明开的足够了。

RE代码:

#include 
int num[500001];
int ans[500001];
int main()
{
    int n, k=1, len, p, r, i;
    int low, mid, high;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0; i= num[i])
                    high = mid - 1;
                else
                    low = mid + 1;
            }
            ans[low] = num[i];
            if(low>len) len++;
        }

        printf("Case %d:\n", k++);
        if(len == 1)
            printf("My king, at most 1 road can be built.\n\n");
        else
            printf("My king, at most %d road can be built.\n\n", len);
    }
    return 0;
}


 

 

你可能感兴趣的:(Hdu 1025 - Constructing Roads In JGShining's Kingdom)