zoukankan      html  css  js  c++  java
  • 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
    ",b[i].m_c,b[i].way);
        printf("
    ");
    }
    /**************************************************************
        Problem: 1007
        User: 2499088506
        Language: C
        Result: Accepted
        Time:0 ms
        Memory:912 kb
    ****************************************************************/</span>

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


  • 相关阅读:
    一致性哈希算法(c#版)
    制作Docker镜像的两种方式
    AWS AutoScaling的一个ScaleDown策略问题以及解决方法
    在CentOS6.6上以replSet方式部署MongoDB集群
    在Docker中安装和部署MongoDB集群
    为Docker容器设置静态IP
    CSS动画的性能分析和浏览器GPU加速
    spark日志配置及问题排查方式。
    Structure Streaming和spark streaming原生API访问HDFS文件数据对比
    SQL On Streaming
  • 原文地址:https://www.cnblogs.com/abc-24990/p/4257542.html
Copyright © 2011-2022 走看看