NYOJ 707 A Simple Problem(结构体排序) 睡前一水~~

链接:click here

题意:

A Simple Problem

时间限制:3000 ms  |  内存限制:65535 KB

难度:2

描述
You know, just as the title imply, this is a simple problem. In a contest, given the team-id, solved, penalty of all the teams, tell me the champion.If the numbers of solved problem
of two team are different, the rank of the one who solves more problems is higher. Otherwise, if the the penalties of two team are different, the rank of the one who has less penalty is higher. Otherwise, the rank of the one whose team-id‘s lexicographic order
is earlier than the other is higher.

输入
The first line of the input is an integer T which stands for the number of test cases. Then T test cases follow.

The first line of test case is a number n, which is the number of team in a contest. Then n line(s) follow. Each line contain a string, and two integers: str, s( 0 <= s <= 15 ), p(0<=p <= 20000), separated by a blank indicating that there is a team whose id
is str,the number of solved problem is s, and the penalty is p.

constraints:

n is in the range of [1 100].

Each team-id does not contain any blanks.

The length of team-id is in the range of[1, 20].

Any two teams will not have the same team-id.

输出
For each test case, output one line with an string indicating the the champion.
样例输入
1
7
Refreshing 5 745
Rock_Restart 4 510
LeadWill 4 679
APTX4869 5 374
WaterCop 5 607
ISAP 5 638
TLE 4 902 
样例输出
APTX4869
来源
SCU Programming Contest 2011
Preliminary

就是按照solved problem,(越大排前), penalties(越小排前),id(字典序排名)的规则排序:

代码:

#include <math.h>
#include <queue>
#include <deque>
#include <vector>
#include <stack>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;
#define Max(a,b) a>b?a:b
#define Min(a,b) a>b?b:a
#define mem(a,b) memset(a,b,sizeof(a))
int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};
const double eps = 1e-6;
const double Pi = acos(-1.0);
static const int inf= ~0U>>2;
static const int maxn =110;
struct node
{
    char id[25];
    int num;
    int time;
}
aa[maxn];
bool cmp(node a,node b)
{
    return a.num!=b.num?a.num>b.num:a.time!=b.time?a.time<b.time:strcmp(a.id,b.id)<0;
}
int main()
{
    int t,n,i;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(i=0; i<n; i++)
            scanf("%s%d%d",aa[i].id,&aa[i].num,&aa[i].time);
        sort(aa,aa+n,cmp);
    //printf("%d\n",aa[0].num);
        printf("%s\n",aa[0].id);
    }
    return 0;
}
        
 

When you want to give up, think of why you persist until now!

时间: 2024-10-13 08:59:25

NYOJ 707 A Simple Problem(结构体排序) 睡前一水~~的相关文章

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

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

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

HDU1225 Football Score 【结构体排序】

Football Score Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2579    Accepted Submission(s): 729 Problem Description Football is one of the greatest games in the world. Lots of people like to

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

Codeforces Round #415 (Div. 2) B. Summer sell-off(贪心+结构体排序)

题目链接:http://codeforces.com/contest/810/problem/B 题意:给定天数和货物可以翻倍的天数,每天都有一定的货物量和顾客数,问怎么样货物才能卖得最多(前一天的货物不会留到下一天,每个顾客只能买一个货物). 简单的贪心问题,贪心策略是:如果两倍的货物量卖出去的更多,就选两倍的,否则就选一倍的. 那一天能卖出去的货物量:min(货物量,顾客数).然后根据结构体排序一下就ok了 1 #include <iostream> 2 #include <algo

【转】 从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法

sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级.本文就sort函数在vector中的用法分为sort函数入门用法与自定义comp比较函数比较结构体这两个最基本的功能讲讲其用法: 1.sort入门: 使用sort需要包含algorithm头文件,完整代码如下 #include<iostream> #include<vector> #include<algorithm>//貌似可以不用,但最好加上. using namespace std

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