CodeForces 151 B 结构体排序。

E - 结构体又来了呦

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d
& %I64u

Submit Status Practice CodeForces
151B

Description

Winters are just damn freezing cold in Nvodsk! That‘s why a group of n friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist
of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size si (that‘s the number of phone numbers). We
know that taxi numbers consist of six identical digits (for example, 22-22-22), the numbers of pizza deliveries should necessarily be decreasing sequences of six different digits (for example, 98-73-21), all other numbers are the girls‘ numbers.

You are given your friends‘ phone books. Calculate which friend is best to go to when you are interested in each of those things (who has maximal number of phone numbers of each type).

If the phone book of one person contains some number two times, you should count it twice. That is, each number should be taken into consideration the number of times it occurs in the phone book.

Input

The first line contains an integer n (1?≤?n?≤?100) — the number of friends.

Then follow n data blocks that describe each friend‘s phone books. Each block is presented in the following form: first goes the line that contains integer si and
string namei (0?≤?si?≤?100)
— the number of phone numbers in the phone book of the i-th friend and the name of the i-th friend. The name
is a non-empty sequence of uppercase and lowercase Latin letters, containing no more than 20 characters. Next si lines
contain numbers as "XX-XX-XX", where X is arbitrary digits from 0 to 9.

Output

In the first line print the phrase "If you want to call a taxi, you should call: ". Then print names of all friends whose phone books contain maximal number of taxi phone numbers.

In the second line print the phrase "If you want to order a pizza, you should call: ". Then print names of all friends who have maximal number of pizza phone numbers.

In the third line print the phrase "If you want to go to a cafe with a wonderful girl, you should call: ". Then print names of all friends who have maximal number of girls‘ phone numbers.

Print the names in the order in which they are given in the input data. Separate two consecutive names with a comma and a space. Each line should end with exactly one point. For clarifications concerning
the output form, see sample tests. It is necessary that you follow the output form strictly. Extra spaces are not allowed.

Sample Input

Input

4
2 Fedorov
22-22-22
98-76-54

3 Melnikov
75-19-09
23-45-67
99-99-98
7 Rogulenko
22-22-22
11-11-11
33-33-33
44-44-44
55-55-55
66-66-66
95-43-21
3 Kaluzhin
11-11-11
99-99-99
98-65-32

Output

If you want to call a taxi, you should call: Rogulenko.
If you want to order a pizza, you should call: Fedorov, Rogulenko, Kaluzhin.
If you want to go to a cafe with a wonderful girl, you should call: Melnikov.

Input

3
5 Gleb
66-66-66
55-55-55
01-01-01
65-43-21
12-34-56
3 Serega
55-55-55
87-65-43
65-55-21
5 Melnik
12-42-12
87-73-01
36-04-12
88-12-22
82-11-43

Output

If you want to call a taxi, you should call: Gleb.
If you want to order a pizza, you should call: Gleb, Serega.
If you want to go to a cafe with a wonderful girl, you should call: Melnik.

Input

3
3 Kulczynski
22-22-22
65-43-21
98-12-00
4 Pachocki
11-11-11
11-11-11
11-11-11
98-76-54
0 Smietanka

Output

If you want to call a taxi, you should call: Pachocki.
If you want to order a pizza, you should call: Kulczynski, Pachocki.
If you want to go to a cafe with a wonderful girl, you should call: Kulczynski.

Hint

In the first sample you are given four friends. Fedorov‘s phone book contains one taxi number and one pizza delivery number, Melnikov‘s phone book only
has 3 numbers of girls, Rogulenko‘s one has 6 taxi
numbers and one pizza delivery number, Kaluzhin‘s one contains 2taxi numbers and one pizza delivery number.

Thus, if you need to order a taxi, you should obviously call Rogulenko, if you need to order a pizza you should call anybody of the following: Rogulenko, Fedorov, Kaluzhin (each
of them has one number). Melnikov has maximal number of phone numbers of girls.

这题的题目还是比较好的, 对结构体的掌握的要求挺高的。先讲下题意。

直接看一个案例。

4
2 Fedorov
22-22-22
98-76-54
3 Melnikov
75-19-09
23-45-67
99-99-98
7 Rogulenko
22-22-22
11-11-11
33-33-33
44-44-44
55-55-55
66-66-66
95-43-21
3 Kaluzhin
11-11-11
99-99-99
98-65-32

Output

If you want to call a taxi, you should call: Rogulenko.
If you want to order a pizza, you should call: Fedorov, Rogulenko, Kaluzhin.
If you want to go to a cafe with a wonderful girl, you should call: Melnikov.

看这个案例。4代表4个人。

然后再输入一个M 和名字。

M代表每个人有M个电话。

然后有一个规则。电话号码相等的有的士服务,电话号码降序排的有披萨服务。其他都是GIRL 服务。

然后输出是先的士,再披萨,然后女孩(服务人的名字)。规则是电话号码类型最多的输出。

比如Rogulenko有6个的士的号码,其他人就两个,一个甚至没有。所以的士只有Rogulenko。

看披萨的输出。除了Melnikov,每个人都有一个披萨的类型的电话(降序的号码),因为此时每个人拥有的相等,所以按顺序输出。(谁名字在前谁输出)。

满足以上规则之后。上代码吧。

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct node
{
	int di,pi,girl,haoma;  //用来统计的士类型的号码几个,披萨类型的号码几个,女孩类型的号码几个。haoma代表名字顺序
	char name[666];  //名字
}
f[666];
bool  cmp1(node a,node b)
{
	if(a.di!=b.di)   //   每个人的士号码的数量不等的话
		return a.di>b.di;  //降序排(因为大的先输出)
	return a.haoma<b.haoma;  //相等的话,按名字的顺序输出
}
bool cmp2(node a,node b)
{
	if(a.pi!=b.pi)
		return a.pi>b.pi;
	return a.haoma<b.haoma; //同上
}
bool cmp3(node a,node b)
{
	if(a.girl!=b.girl)
		return a.girl>b.girl;
	return a.haoma<b.haoma; //同上
}
int main()
{
    int i,j,n,m;
	while(~scanf("%d",&n))
	{
		char dh[6666];
		for(i=0;i<n;i++)
		{
			scanf("%d%s",&m,f[i].name);
			f[i].haoma=i;  //这个主要是输出名字的顺序。
			for(j=0;j<m;j++)
			{
				scanf("%s",dh);
				if(dh[0]==dh[1]&&dh[0]==dh[3]&&dh[3]==dh[4]&&dh[4]==dh[6]&&dh[6]==dh[7])
					f[i].di++;  // 满足所有数字相等规则,的士类型的号码数量加一
				else if(dh[0]>dh[1]&&dh[1]>dh[3]&&dh[3]>dh[4]&&dh[4]>dh[6]&&dh[6]>dh[7])
					f[i].pi++;  //  满足降序排的数字,披萨类型的号码数量加已。
				else
					f[i].girl++;//其他全是女孩类型的号码
			}
		}
		sort(f,f+n,cmp1);  // 结构体排序
        printf("If you want to call a taxi, you should call: %s",f[0].name);  //第一个人的号码数量肯定最多,直接输出
        for( i=1;i<n&&f[i].di==f[i-1].di;i++)    //比较后面的是否跟第一个人相等,相等的话也输出。
			printf(", %s",f[i].name);
        printf(".\n");
		sort(f,f+n,cmp2);
		printf("If you want to order a pizza, you should call: %s",f[0].name);
        for( i=1;i<n&&f[i].pi==f[i-1].pi;i++)
			printf(", %s",f[i].name);
        printf(".\n");  //同上
        sort(f,f+n,cmp3);
		printf("If you want to go to a cafe with a wonderful girl, you should call: %s",f[0].name);
        for( i=1;i<n&&f[i].girl==f[i-1].girl;i++)
			printf(", %s",f[i].name);
        printf(".\n");  //同上

    }
    return 0;
}
时间: 2024-10-12 10:12:05

CodeForces 151 B 结构体排序。的相关文章

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

C++结构体排序

在C++中,对结构体的排序方式比C语言丰富的多.在C语言中,我们主要是通过qsort进行排序操作(抛开手写排序算法不说). 在C++<algorithm>中,有一个十分强大的排序函数sort,他的内部综合了许多种排序算法,因此非常高效.并且,用它来对结构体排序也十分方便. 先贴一段示例代码: 1 #include <cstdio> 2 #include <queue> 3 #include <vector> 4 #include <algorithm&

结构体排序

经常碰到结构体排序的问题,在此总结一下.以一个简单的例题开始: 例1.有三个人(Person结构体),每个人都有name(string型)和age(int型)两个属性,现在需要按照下面的规则排序:先以姓名按从小到大排序(如abc<abd),如果姓名相同,则按照年龄从大到小排序. #include<iostream> #include<string> using namespace std; struct Person{ string name; int age; }; voi

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

最小生成树模板+并查集(隐藏)+结构体排序模板

minn[101],g[101][101],u[101]; memset(u,1,sizeof(u)); memset(minn,0x7f,sizeof(minn)); minn[1]=0; u[1]=0; i,j,k,m; total=0; for(i=1;i<=n;i++) { k=0; for(j=1;j<=n;j++) if(u[j]&&(minn[k]>minn[j])) k=j; u[k]=0; for(j=1;j<=n;j++) if(u[j]&

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 2409 Team Arrangement (结构体排序)

题目链接:HDU 2409 Team Arrangement 题意:给出22个人(编号,名字,踢的位置,在队里的时间),让我们选DD-MM-SS的阵型+一个守门员.在选出队长(时间在最久的就是队长,时间相同编号大为队长),选人的顺序是从编号小的开始. 结构体排序就好了,注意出输出是按队长,D,M,S的顺序,选队长记录队长的编号(而不是下标,我的代码之后还要排序). AC代码: #include<stdio.h> #include<string.h> #include<algo