203C Photographer

第一道A的纠结;

简单题,WA了几次,最后发现AC的代码 sort 的 cmp 返回的是 bool 型,注意到这点,就 A 了,数据是不会超范围的;

# include <cstdio>

# include <cstring>

# include <algorithm>



# define N 100005



using namespace std;



int n, d, a, b;

int c[N], p[N];

char f[N];



bool cmp(const int &x, const int &y)

{

    return c[x] < c[y];

}



void init(void)

{

    int i, x, y;



    memset(f+1, 0, sizeof(f[0])*n);

    for (i = 1; i <= n; ++i)

    {

        scanf("%d%d", &x, &y);

        c[i] = x*a + y*b;

        p[i] = i;

    }

    sort(p+1, p+n+1, cmp);

}



void solve(void)

{

    int rem, i, cnt;



    cnt = 0;

    rem = d;

    for (i = 1; i <= n; ++i)

    {

        if (rem >= c[p[i]])

        {

            ++cnt;

            f[p[i]] = 1;

            rem -= c[p[i]];

        }

        else break;

    }

    printf("%d\n", cnt);

    for (i = 1; i <= n; ++i) if (f[i])

    {

        --cnt;

        printf("%d", i);

        if (cnt == 0) {putchar('\n'); break;}

        else putchar(' ');

    }

}



int main()

{

    while (~scanf("%d%d%d%d", &n, &d, &a, &b))

    {

        init();

        solve();

    }



    return 0;

}

http://codeforces.com/problemset/problem/203/C

你可能感兴趣的:(Graph)