online_judge_1007

<pre name="code" class="plain"><span style="font-size:24px;">#include <stdio.h>
#include <stdlib.h>
typedef struct guojia
{
     int gold;
     int prize;
     int population;
}node;
typedef struct shu
{
    int m_c;
    int way;
}result;
 
result sort(node *,int,int);
void input(node *,int);
void output(result *,int);
 
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        node *a=(node *)malloc(sizeof(node)*n);
        node *d=(node *)malloc(sizeof(node)*m);
        result *b=(result *)malloc(sizeof(result)*m);
        int *c=(int *)malloc(sizeof(int)*m);
        int i;
        input(a,n);
        for(i=0;i<m;i++)
        {
            scanf("%d",&c[i]);
            d[i]=a[c[i]];
        }
        for(i=0;i<m;i++)
            b[i]=sort(d,i,m);
        output(b,m);
    }
    return 0;
}
void input(node d[],int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        scanf("%d",&d[i].gold);
        scanf("%d",&d[i].prize);
        scanf("%d",&d[i].population);
    }
}
result sort(node *a,int num,int n)
{
    result temp;
    int i,n1=1,n2=1,n3=1,n4=1;
    for(i=0;i<n;i++)
    {
        if(a[i].gold>a[num].gold) n4++;
        if(a[i].prize>a[num].prize) n3++;
        if(a[i].gold*a[num].population>a[num].gold*a[i].population) n2++;
        if(a[i].prize*a[num].population>a[num].prize*a[i].population) n1++;
    }
    if(n4<=n3&&n4<=n2&&n4<=n1)
    {
        temp.m_c=n4;
        temp.way=1;
    }
    else if(n3<n4&&n3<=n2&&n3<=n1)
    {
        temp.m_c=n3;
        temp.way=2;
    }
    else if(n2<n4&&n2<n3&&n2<=n1)
    {
        temp.m_c=n2;
        temp.way=3;
    }
    else
    {
        temp.m_c=n1;
        temp.way=4;
    }
    return temp;
}
void output(result *b,int m)
{
    int i;
    for(i=0;i<m;i++)
        printf("%d:%d\n",b[i].m_c,b[i].way);
    printf("\n");
}
/**************************************************************
    Problem: 1007
    User: 2499088506
    Language: C
    Result: Accepted
    Time:0 ms
    Memory:912 kb
****************************************************************/</span>


<span style="font-size:18px;">很多时候看起来容易,做起来却是十分难。这样一道题目,我琢磨了几个小时,提交了五次才成功!
学习编程不光要坚持练习,还要多总结。也许是我的变成习惯不好吧!第一次提交失败对我来说是很
可怕的。只有通过全篇检查才能发现错误。很多时候也许是题目做的太少了吧!

</span>


posted on 2015-01-16 17:53  赛亚人  阅读(88)  评论(0编辑  收藏  举报