HDU 2409 Team Arrangement (结构体排序)

题目链接:HDU 2409 Team Arrangement

题意:给出22个人(编号,名字,踢的位置,在队里的时间),让我们选DD-MM-SS的阵型+一个守门员。在选出队长(时间在最久的就是队长,时间相同编号大为队长),选人的顺序是从编号小的开始。

结构体排序就好了,注意出输出是按队长,D,M,S的顺序,选队长记录队长的编号(而不是下标,我的代码之后还要排序)。

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
    int num;
    char name[50];
    char p[5];
    int time;
    int ok;
};
struct node p[50];

int get_time(char s[])
{
    int len=strlen(s),i;
    int t1,t2,flag,sum;
    t1=t2=0;
    flag=0;
    sum=0;
    for(i=0;i<len;i++)
    {
        if(s[i]==' ')
        {
            sum+=(t2-t1+1);
            flag=t1=t2=0;
            continue;
        }
        if(s[i]=='-')
        {
            flag=1;
            continue;
        }
        if(!flag)
            t1=t1*10+s[i]-'0';
        else
            t2=t2*10+s[i]-'0';
    }
    sum+=t2-t1+1;
    return sum;
}

bool cmp(node a,node b)
{
    return a.num<b.num;
}

bool cmp2(node a,node b)
{
    if(a.ok!=b.ok)
        return a.ok<b.ok;
    return a.num<b.num;
}

int main()
{
    int i;
    char s[500],hh[500];
    int dd,mm,ss;
    int flag = 0;
    while(scanf("%d",&p[0].num)!=EOF,p[0].num)
    {
        for(i=0;i<22;i++)
            p[i].ok=0;
        int temp;
        scanf("%s %s",p[0].name,p[0].p);
        getchar();
        gets(s);
        p[0].time=get_time(s);
        for(i=1;i<22;i++)
        {
            scanf("%d %s %s",&p[i].num,p[i].name,p[i].p);
            getchar();
            gets(s);
            p[i].time=get_time(s);
            //printf("%d....\n",p[i].time);
        }
        scanf("%s",hh);
        dd=hh[0]-'0';
        mm=hh[2]-'0';
        ss=hh[4]-'0';
        int mark=0;
        sort(p,p+22,cmp);
        for(i=0;i<22;i++)
        {
            if(p[i].p[0]=='G')
            {
                p[i].ok=1;
                mark=1;
                break;
            }
        }
        int count=0;
        for(i=0;i<22;i++)
        {
            if(p[i].p[0]=='D')
            {
                if(dd==0)
                    break;
                p[i].ok=2;
                dd--;
            }
        }
        for(i=0;i<22;i++)
        {
            if(p[i].p[0]=='M')
            {
                if(mm==0)
                    break;
                p[i].ok=3;
                mm--;
            }
        }
        for(i=0;i<22;i++)
        {
            if(p[i].p[0]=='S')
            {
                if(ss==0)
                    break;
                p[i].ok=4;
                ss--;
            }
        }
        if(mark!=1 || dd!=0 || mm!=0 || ss!=0)//没选满
        {
            printf("IMPOSSIBLE TO ARRANGE\n\n");
            continue;
        }
        int maxn=-1,max_i;
        for(i=0;i<22;i++)
        {
            if(p[i].ok)
            {
                if(p[i].time>=maxn)
                {
                    maxn=p[i].time;
                    max_i=i;
                    if(p[i].time==maxn)
                    {
                        if(p[i].num>p[max_i].num)
                            max_i=i;
                    }
                }
            }
        }
        printf("%d %s %s\n",p[max_i].num,p[max_i].name,p[max_i].p);
        int col=p[max_i].num;
        sort(p,p+22,cmp2);
        for(i=0;i<22;i++)
        {
            if(p[i].ok && col!=p[i].num)
                printf("%d %s %s\n",p[i].num,p[i].name,p[i].p);
        }
        printf("\n");
    }
    return 0;
}
时间: 2024-08-06 03:45:05

HDU 2409 Team Arrangement (结构体排序)的相关文章

POJ 3339 &amp; HDU 2409 Team Arrangement(结构体)

题目链接: PKU:http://poj.org/problem?id=3339 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2409 Description Barry Bennett, the coach of the Bings football team, wants to arrange his team for an important match against the Bangs. He decides on the formati

【结构体排序】hdu 2409 Team Arrangement

[结构体排序]hdu 2409 Team Arrangement 题目链接:hdu 2409 Team Arrangement 题目大意 给出22个球员的各种信息,要求按照给出的阵形选择球员和队长共11人: 选择球员的规则是:同角色的球员按照编号从小到大选择,直到选够此角色的人数: 选择队长的规则是:在所有已经被选择为某角色的球员中,选择服役时间最长的那个球员, 如果服役时间时间相同,就选择编号较大的那一个球员: 2006 Asia Regional Tehran(伊朗首都德黑兰)的第一题,题意

hdu 2093 考试排名(结构体排序)

对"到文件结束"理解 代码: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct node { char name[20]; int num; int t; void init() { t=0; num=0; } }; int cmp(const node a,const node b) { if(a.num==b.num&&am

HDU 1084 [What Is Your Grade?] 结构体排序

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1084 题目大意:共5道题,N个学生.做出5道满分,0道50分.做出1-4道的同学,若在前50%(向下取整),则获得95.85.75.65,若在后50%则获得90.80.70.60. 关键思想:结构体排序 //结构体排序,考虑边界 #include <iostream> #include <algorithm> #include <cmath> #include <me

hdu 5702 Solving Order(结构体排序 水题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5702 Solving Order Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 184    Accepted Submission(s): 135 Problem Description Welcome to HDU to take p

hdu 1070(结构体排序)

Milk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13639    Accepted Submission(s): 3328 Problem Description Ignatius drinks milk everyday, now he is in the supermarket and he wants to choose

HDU 1862 EXCEL排序(结构体排序)

EXCEL排序 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 16387    Accepted Submission(s): 6137 Problem Description Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能. Input 测试输入包含若干测试用例.每个测试用例的第1行包含两个整数 N (<=1

hdu 1069 Monkey and Banana (结构体排序,也属于简单的dp)

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7770    Accepted Submission(s): 4003 Problem Description A group of researchers are designing an experiment to test the IQ of a

HDOJ 1009. Fat Mouse&#39; Trade 贪心 结构体排序

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 56784    Accepted Submission(s): 19009 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g