九度OJ 1491-1500(5/10)

1491(未完成)

1492

#include <stdio.h>

#define M 100
#define N 10

int main(void)
{
    int n, m, i, j, k, r;
    int a[M][M];
    int sum, min;

    while (scanf("%d%d", &m, &n) != EOF)
    {
        for(i=0; i<m; i++)
        {
            for (j=0; j<m; j++)
            {
                scanf("%d", &a[i][j]);
            }
        }
        min = 0;
        for(i=0; i<=m-n; i++)
        {
            for (j=0; j<=m-n; j++)
            {
                if (j == 0)
                {
                    sum = 0;
                    for (k=i; k<n+i; k++)
                    {
                        for (r=0; r<n; r++)
                        {
                            sum += a[k][r];
                        }
                    }
                    if (i == 0)
                        min = sum;
                }
                else
                {
                    for (k=i; k<n+i; k++)
                        sum += a[k][j+n-1] - a[k][j-1];
                }
                if (sum < min)
                    min = sum;
            }
        }
        printf("%d\n", min);
    }

    return 0;
}
/************************************************************** Problem: 1492 User: liangrx06 Language: C Result: Accepted Time:30 ms Memory:912 kb ****************************************************************/

1493

#include <stdio.h>
#include <math.h>

int zdgys(int a, int b)
{
    if (b == 0)
        return a;
    return zdgys(b, a%b);
}

int main()
{
    int i, a, b;
    int max;
    while(scanf("%d%d", &a, &b) != EOF)
    {
        if (a >= b)
            max = zdgys(a, b);
        else
            max = zdgys(b, a);

        int count = 0;
        for (i=1; i<sqrt(max); i++)
        {
            if (max%i == 0)
                count ++;
        }
        count *= 2;
        if ( ((int)sqrt(max)) * ((int)sqrt(max))  == max)
            count ++;

        printf("%d\n", count);
    }
    return 0;
}
/************************************************************** Problem: 1493 User: liangrx06 Language: C Result: Accepted Time:20 ms Memory:928 kb ****************************************************************/

1494-1497(未完成)

1498

#include <stdio.h>

int n;
char op[15];

void print()
{
    int i;
    for (i=1; i<=n; i++)
    {
        printf("%d", i);
        if (i < n)
            printf("%c", op[i]);
    }
    printf("\n");
}

int compute()
{
    int i, a, b;
    char c;
    a = 0;
    b = 1;
    c = '+';
    for (i=1; i<n; i++)
    {
        if (op[i] == ' ')
        {
            if (i+1 >= 10)
                b = 100*b+(i+1);
            else
                b = 10*b+(i+1);
        }
        else
        {
            if (c == '+')
                a = a+b;
            else
                a = a-b;
            c = op[i];
            b = i+1;
        }
    }
    if (c == '+')
        a = a+b;
    else
        a = a-b;
    return a;
}

void DFS(int i)
{
    if (i == n)
    {
        int res = compute();
        if (res == 0)
            print();
        return;
    }
    op[i] = ' ';
    DFS(i+1);
    op[i] = '+';
    DFS(i+1);
    op[i] = '-';
    DFS(i+1);
}

int main(void)
{
    while (scanf("%d", &n) != EOF)
    {
        DFS(1);
    }

    return 0;
}
/************************************************************** Problem: 1498 User: liangrx06 Language: C Result: Accepted Time:420 ms Memory:912 kb ****************************************************************/

1499

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define N 10000

typedef struct node {
    int st;
    int ed;
    int val;
} Prog;

int cmp(const void *a, const void *b)
{
    return ((Prog *)a)->ed - ((Prog *)b)->ed;
}

int main(void)
{
    int n, i, j;
    Prog b[N+1];
    int m[N+1];

    while (scanf("%d", &n) != EOF)
    {
        for(i=1; i<=n; i++)
            scanf("%d%d%d", &b[i].st, &b[i].ed, &b[i].val);
        qsort(b+1, n, sizeof(b[0]), cmp);

        memset(m, 0, sizeof(m));
        for(i=1; i<=n; i++)
        {
            m[i] = (b[i].val>m[i-1]) ? b[i].val : m[i-1];
            for (j=i-1; j>=0; j--)
            {
                if (b[i].st >= b[j].ed && m[i] < m[j]+b[i].val)
                    m[i] = m[j] + b[i].val;
            }
        }

        printf("%d\n", m[n]);
    }

    return 0;
}
/************************************************************** Problem: 1499 User: liangrx06 Language: C Result: Accepted Time:340 ms Memory:1004 kb ****************************************************************/

1500

#include <stdio.h>

#define N 1000000

int big[N], count;
int up[N], down[N];

void print(int x[N], int c)
{
    for (int i=0; i<c; i++)
        printf("%d ", x[i]);
    printf("\n");
}

int binSearch(int begin, int end, int k)
{
    if (end == -1)
        return -1;
    if (begin == end)
    {
        if (big[begin] < k)
            return begin;
        else
            return -1;
    }
    int mid = (begin+end)/2;
    if (big[mid+1] >= k)
        return binSearch(begin, mid, k);
    else
        return binSearch(mid+1, end, k);
}

int insert(int k)
{
    int j;
    j = binSearch(0, count-1, k);
    //printf("j=%d, count=%d\n", j, count);
    if (j == count-1 || big[j+1] > k)
    {
        big[j+1] = k;
        if (j == count-1)
            count ++;
    }
    //print(big, count);
    return j+2;
}

int main(void)
{
    int a[N], n, i;
    while (scanf("%d", &n) != EOF)
    {
        for(i=0; i<n; i++)
            scanf("%d", &a[i]);

        count = 0;
        for(i=0; i<n; i++)
            up[i] = insert(a[i]);
        count = 0;
        for(i=n-1; i>=0; i--)
            down[i] = insert(a[i]);

        int max = 0;
        for (i=0; i<n; i++)
        {
            if (up[i]+down[i] > max)
                max = up[i]+down[i];
        }
        printf("%d\n", n-max+1);
    }

    return 0;
}
/************************************************************** Problem: 1500 User: liangrx06 Language: C Result: Accepted Time:1100 ms Memory:16468 kb ****************************************************************/

你可能感兴趣的:(九度OJ 1491-1500(5/10))