hdu 3554 Another Contest

来源:互联网 发布:数据分析专业 电脑推荐 编辑:程序博客网 时间:2024/05/11 14:56

简单模拟,关键在于排序。

#include <stdio.h>#include<string.h>#include<iostream>#define maxn 1005using namespace std;struct Node{int id,sum,n;}x[maxn];int tmp[maxn];bool cmp(Node a, Node b){    if(a.sum!=b.sum)return a.sum>b.sum;    else if(a.n!=b.n)return a.n>b.n;    else return a.id<b.id;}int main(){    int i, j, n, s, p, t,rank;    while(scanf("%d%d%d", &n,&s,&p)!=EOF)    {        for(i=1; i<=s; i++)        {            x[i].id=i;x[i].sum=0;x[i].n=0;        }        for(i=1; i<=n; i++)         {            t=0;            for(j=1; j<=s; j++)            {                 scanf("%d", &tmp[j]);                 if(tmp[j]==0)                      t++;            }            for(j=1; j<=s; j++){                if(tmp[j]==1)                {                    x[j].n++;                    x[j].sum+=t;                }            }        }        sort(x+1, x+s+1, cmp);        for(i=1; i<=s; i++)        {            if(x[i].id==p)            {                printf("%d %d\n", x[i].sum, i);                break;            }        }    }    return 0;}


 

原创粉丝点击