WD

XIAOPANGCHIROU 

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    int T, i, j , n,  m, x, a[1001], b[1001];
    int V=0, t = 0, happy=0;
    scanf("%d", &T);
    while(T--)
    {
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        scanf("%d%d",&n, &x);
        V = 0; happy = 0, t = 0;
        for(i=0; i<n; i++){
            scanf("%d %d", &a[i], &b[i]);
            m+=a[i];
        }
    for(i=0; i<n-1; i++)
        for(j=i+1; j<n; j++)
        {
            if(b[i] < b[j])
            {
                t = b[i];
                b[i] = b[j];
                b[j] = t;

                t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
        }
for(i=0; i<n; i++)
{
    V += a[i];
    if(V >= x)
       break;
       if(b[i] >= 0)
    happy += a[i]*b[i];
   // printf("###%d\n", happy);

}
  if(m >= x)
       t = (x-V+a[i])*b[i];
    //printf("!!!%d\n", t);
    printf("%d\n", t+happy);
    }
 return 0;
}
PARTY

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int a[100][100], b[1000];
int main()
{
    int T, n, i, j, t, k;
    int sum1=0, sum2=0;
    scanf("%d", &T);
    while(T--)
    {

        scanf("%d", &n);
        sum1 = 0;  sum2 = 0;
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        for(k=0; k<n; k++)
        {
            scanf("%d", &b[k]);
            if(b[k] > 0)
             sum1 += b[k];
        }
        for(i=0; i<n; i++)
           for(j=0; j<n; j++)
           {
               scanf("%d", &a[i][j]);
                if(a[i][j] >= 0 && i < j)
                    sum2 += a[i][j];
           }
           t = sum1 + sum2;
         printf("%d\n", t);
    }
    return 0;
}

 

GOUGUDINGLI

#include<stdio.h>
void qsort(int a[], int l, int r)
    {
        int x = a[l], i = l, j = r;
        if(l >= r) return ;
        while(i < j)
        {
            while(i<j && a[j] <= x) j--;
                a[i] = a[j];
            while(i<j && a[i] >= x) i++;
                a[j] = a[i];
        }
    a[i] = x;
    qsort(a, l, i-1);
    qsort(a, i+1, r);
}
int main()
{
    int T, n, i, j, k, count=0;
    int a[1001];
    scanf("%d", &T);
    while(T--)
    {
        count=0;
        scanf("%d", &n);
        for(i=0; i<n; i++)
            scanf("%d", &a[i]);
      qsort(a, 0, n-1);
        for(i=0; i<n-2; i++)
            for(k=i+1; k<n-1; k++)
                for(j=k+1; j<n; j++)
                {
                    if(a[i]*a[i] == a[k]*a[k] + a[j]*a[j])
                    count++;
                    if(a[i]*a[i] > a[k]*a[k] + a[j+1]*a[j+1] && a[i]*a[i] > a[k]*a[k] + a[j]*a[j])
                       break;
                }
            printf("%d\n", count);
    }
    return 0;
}

posted @ 2014-05-25 17:12  6bing  阅读(114)  评论(0编辑  收藏  举报