UVALive 7077 - Song Jiang's rank list(模拟)

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5085

题目大意:给n个人以及每个人的名字s和他能杀死的敌人数m,将这些人按能杀死的敌人数进行排名并输出,m次查询,每次查询输出这个人的两个排名,

一个是他在他排名之前(他不能杀死,注:他不能杀死与他杀死敌人数相等的人)的人数 + 1, 一个是他排名之前与他杀死敌人数相等的人数 + 1

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>

using namespace std;

const int N = 210;

struct st
{
    int m, add, same, f;
    char s[60];
} node[N], a[N];

int cmp(const void *a, const void *b)
{
    st *s1 = (st *)a , *s2 = (st *)b;
    if(s1->m != s2->m)
        return s2->m - s1->m;
    else
        return strcmp(s1->s, s2->s);
        //按字典序排列
}

int main()
{
    int n, i, j, m;
    while(scanf("%d", &n), n)
    {
        for(i = 0 ; i < n ; i++)
        {
            scanf("%s%d", node[i].s, &node[i].m);
            node[i].same = node[i].f = 0;
        }
        qsort(node, n, sizeof(node[0]), cmp);
        scanf("%d", &m);
        for(i = 1 ; i <= m ; i++)
        {
            scanf("%s", a[i].s);
            for(j = 0 ; j < n ; j++)
            {
                if(strcmp(a[i].s, node[j].s) == 0)
                    a[i].add = j;
            }
        }//a[i].add就是第i个人的排名,排名从第0名开始
        for(i = 0 ; i < n - 1 ; i++)
        {
            for(j = i + 1 ; j < n ; j++)
            {
                if(node[i].m == node[j].m)
                    node[j].same++;
            }
        }//统计他排名之前与他杀死敌人数相等的人数
        for(i = 0 ; i < n ; i++)
            printf("%s %d\n", node[i].s, node[i].m);
        for(i = 1 ; i <= m ; i++)
        {
            if(node[a[i].add].same >= 1)
                printf("%d %d\n", a[i].add - node[a[i].add].same + 1, node[a[i].add].same + 1);
            else
                printf("%d\n", a[i].add - node[a[i].add].same + 1);
        }
    }
    return 0;
}

UVALive 7077 - Song Jiang's rank list(模拟)

时间: 2024-10-12 18:54:37

UVALive 7077 - Song Jiang's rank list(模拟)的相关文章

hdu 5131 Song Jiang&#39;s rank list(模拟)

Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 662    Accepted Submission(s): 329 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'

[ACM] HDU 5131 Song Jiang&#39;s rank list (模拟)

Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 36    Accepted Submission(s): 18 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'an

hdoj 5131 Song Jiang&#39;s rank list 【模拟】

Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 653    Accepted Submission(s): 323 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'

UVALive 7077 Little Zu Chongzhi&#39;s Triangles (有序序列和三角形的关系)

这个题……我上来就给读错了,我以为最后是一个三角形,一条边可以由多个小棒组成,所以想到了状态压缩各种各样的东西,最后成功了……结果发现样例过不了,三条黑线就在我的脑袋上挂着,改正了以后我发现N非常小,想到了回溯每个棍的分组,最多分5组,结果发现超时了……最大是5^12 =  244,140,625,厉害呢…… 后来想贪心,首先想暴力出所有可能的组合,结果发现替换问题是一个难题……最后T T ,我就断片了.. 等看了别人的办法以后,我才发现我忽视了三角形的特性,和把数据排序以后的特点. 如果数据从

UVALive 6093 Emergency Room --优先队列实现的模拟

题意:给n个医生,这些医生有一个上班时间,然后给一些病人,病人有一个到达的时间,以及一些诊断,诊断有property(优先级)和duration(诊断时间)这两个属性,每个病人可能要诊断多次,最后问每个病人的全部疗程完成离开医院的时间是多少. 分析:用优先队列存储诊断,病人,然后模拟一个诊断过程,完成病人的个数等于病人数的时候就结束.具体看代码吧. 代码: #include <iostream> #include <cstdio> #include <cstring>

Song Jiang&#39;s rank list(杭电oj5131)(2014ACM/ICPC亚洲区广州站)

Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 168    Accepted Submission(s): 91 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'a

Song Jiang&#39;s rank list

 Song Jiang's rank list Time Limit:1000MS     Memory Limit:512000KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 5131 Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'an -- an writer of Yuan and Ming dy

HDU 5131 Song Jiang&#39;s rank list (结构体+MAP,2014广州现场赛)

题目链接:HDU 5131 Song Jiang's rank list 题意:对给出的好汉按杀敌数从大到小排序,若相等,按字典序排.M个询问,询问名字输出对应的主排名和次排名.(排序之后)主排名是在该名字前比他杀敌数多的人的个数加1,次排名是该名字前和他杀敌数相等的人的个数加1,(也就是杀敌数相等,但是字典序比他小的人数加1). AC代码: #include <stdio.h> #include <string> #include <map> #include <

hdu 5131 Song Jiang&#39;s rank list

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5131 Song Jiang's rank list Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'an -- an writer of Yuan and Ming dynasty. <Shui Hu Zhuan>is one of the Four Great Classical