zoukankan      html  css  js  c++  java
  • (HDOJ 1031)Design T-Shirt

    http://acm.hdu.edu.cn/showproblem.php?pid=1031

     

    毫无疑问的水题,和本人前面所写的博客

    POJ 2092 Grandpa is Famous 结构体的巧妙运用

    处理方法一模一样。

    用结构体加上sort排序,速度ac。

    但是有一个细节,题目说如果是多组的话输出序号小的,我的代码中并没有进行处理,一样可以a。

    这肯定有原因:多解的情况,只能是有大于k的元素的得分相同,如果是相同的话,排序时,不会移动他们,所以按大到小排列后,输出前k个,正好就是序号最小的。

    代码如下:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 #define M 1010
     6 #define mem0(f) memset(f,0,sizeof(f))
     7 struct element
     8 {
     9     int xuhao;//装序号
    10     double mark;//装得分
    11 }elem[M];
    12 bool cmp(element a,element b)
    13 {
    14     return a.mark>b.mark;
    15 }
    16 bool cmpp(element a,element b)
    17 {
    18     return a.xuhao>b.xuhao;
    19 }
    20 int n,m,k;
    21 int main()
    22 {//序号从1开始
    23     while(~scanf("%d%d%d",&n,&m,&k))
    24     {
    25         mem0(elem);
    26         for(int i=0;i<n;i++)
    27         {
    28             for(int p=0;p<m;p++)
    29             {
    30                 double t;
    31                 scanf("%lf",&t);
    32                 elem[p].mark+=t;
    33                 elem[p].xuhao=p;
    34             }
    35         }
    36         sort(elem,elem+m,cmp);//按得分排顺序,
    37         sort(elem,elem+k,cmpp);
    38         for(int i=0;i<k;i++)
    39         {
    40             if(i==k-1)
    41             printf("%d
    ",elem[i].xuhao+1);
    42             else
    43                 printf("%d ",elem[i].xuhao+1);
    44         }
    45     }
    46     return 0;
    47 
    48 }
  • 相关阅读:
    向eureka注册正确的ip地址
    sleuth + zipkin 链路分析
    Yii2的整体结构概览
    Redis实现消息队列
    Redis使用场景梳理
    redis基础知识
    TCP服务
    数据结构-队列
    看见
    线性表的链式存储结构
  • 原文地址:https://www.cnblogs.com/plank-george-zzo/p/3245053.html
Copyright © 2011-2022 走看看