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 bootshl at 2008-07-29 12:41:55 on Problem 1065
#include <stdio.h>
#include <stdlib.h>


struct stick{
    int l;
    int w;
}a[5001];

int account(int n);

int main(void)
{
    int ncase, i, ndata, j, k;
    struct stick key, temp;
    while (scanf("%d", &ncase) == 1) {
        for (i = 0; i < ncase; i++) {
            scanf("%d", &ndata);
            for (j = 0; j < ndata; j++)
                scanf("%d%d", &a[j].l, &a[j].w);
            /*插入排序*/
            for (j = 1; j < ndata; j++) {
                key = a[j];
                for (k = j-1; key.w < a[k].w && k >= 0; k--) {
                    a[k + 1] = a[k];
                }
                a[k + 1] = key;
                if (a[k].w == a[k + 1].w && a[k].l > a[k + 1].l) {
                    temp = a[k];
                    a[k] = a[k + 1];
                    a[k + 1] = temp;
                }
            }
            /*for (j = 0; j < ndata; j++)
                printf("(%2d, %2d)", a[j].l, a[j].w);*/
            printf("%d\n", account(ndata));
        }
    }
    return 0;
}



int account(int n)
{
    int i, sum, pos;
    sum = 0;
    i = 0;
    pos = 0;
    while (i < n) {
        while(i + 1 < n && a[i].l <= a[i + 1].l) {
            i++;
            pos = i + 1;
        }
        sum++;
        i++;
    }
    return sum;
}

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