CF151B Phone Numbers 题解
Content
在一座城市中,每个人的电话号码都是由六位整数组成的,例如 11-45-14。
现在有 \(n\) 个人,第 \(i\) 个人有 \(s_i\) 个人的电话号码。已知:
- 出租车司机的电话号码由六个相同的数字构成(如 66-66-66)。
- 披萨外卖的电话号码由六个递减的数字构成(如 65-43-21)。
- 其他的电话号码都是女生的。
现在给出这 \(n\) 个人所拥有的电话号码。众所周知,找一个拥有某种事情相关的人的电话号码最多的人办这件事总会很靠谱。你需要求出你在办某件事的时候应该找哪些人。
数据范围:\(1\leqslant n\leqslant 100\),\(0\leqslant s_i\leqslant 100\)。
Solution
这题是一道较为简单的模拟题。
我们利用 scanf 的特性,按照格式输入没个电话号码的六个数字,然后按照题目给出的规则将每个电话号码归入题目给出的类型中,同时统计每个人所拥有某种类型的电话号码的数量。
统计完以后,分别按照拥有某种类型的电话号码的数量降序排列,然后找出拥有和最多数量相同的人,最后再按照输入顺序输出即可。
Code
int n, num[107], cnt;
struct node {
string name;
int x[107][7], taxi, pizza, girl, id;
}a[107], ans1[107], ans2[107], ans3[107];
ib cmp1(const node& tmp1, const node& tmp2) {return tmp1.taxi > tmp2.taxi;}
ib cmp2(const node& tmp1, const node& tmp2) {return tmp1.pizza > tmp2.pizza;}
ib cmp3(const node& tmp1, const node& tmp2) {return tmp1.girl > tmp2.girl;}
ib cmpid(const node& tmp1, const node& tmp2) {return tmp1.id < tmp2.id;}
int main() {
n = Rint;
F(i, 1, n) {
num[i] = Rint, a[i].id = i; cin >> a[i].name;
F(j, 1, num[i]) scanf("%1d%1d-%1d%1d-%1d%1d", &a[i].x[j][1], &a[i].x[j][2], &a[i].x[j][3], &a[i].x[j][4], &a[i].x[j][5], &a[i].x[j][6]);
}
F(i, 1, n) {
F(j, 1, num[i]) {
int fl1 = 1, fl2 = 1;
F(k, 1, 6) if(a[i].x[j][k] != a[i].x[j][1]) {fl1 = 0; break;}
F(k, 2, 6) if(a[i].x[j][k] >= a[i].x[j][k - 1]) {fl2 = 0; break;}
if(fl1) a[i].taxi++;
else if(fl2) a[i].pizza++;
else a[i].girl++;
}
}
sort(a + 1, a + n + 1, cmp1);
int tmp = a[1].taxi;
sort(a + 1, a + n + 1, cmpid);
printf("If you want to call a taxi, you should call: ");
F(i, 1, n) if(a[i].taxi == tmp) ans1[++cnt] = a[i];
F(i, 1, cnt) cout << ans1[i].name << (i == cnt ? ".\n" : ", ");
sort(a + 1, a + n + 1, cmp2);
printf("If you want to order a pizza, you should call: ");
tmp = a[1].pizza, cnt = 0;
sort(a + 1, a + n + 1, cmpid);
F(i, 1, n) if(a[i].pizza == tmp) ans2[++cnt] = a[i];
F(i, 1, cnt) cout << ans2[i].name << (i == cnt ? ".\n" : ", ");
sort(a + 1, a + n + 1, cmp3);
printf("If you want to go to a cafe with a wonderful girl, you should call: ");
tmp = a[1].girl, cnt = 0;
sort(a + 1, a + n + 1, cmpid);
F(i, 1, n) if(a[i].girl == tmp) ans3[++cnt] = a[i];
F(i, 1, cnt) cout << ans3[i].name << (i == cnt ? ".\n" : ", ");
return 0;
}
CF151B Phone Numbers 题解的更多相关文章
- CF55D Beautiful numbers 题解
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...
- Hdoj 1905.Pseudoprime numbers 题解
Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1 ...
- Hdoj 1058.Humble Numbers 题解
Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...
- [LeetCode] Add Two Numbers题解
Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. Th ...
- poj 1995 Raising Modulo Numbers 题解
Raising Modulo Numbers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6347 Accepted: ...
- CF1265B Beautiful Numbers 题解
Content 给定一个 \(1\sim n\) 的排列,请求出对于 \(1\leqslant m\leqslant n\),是否存在一个区间满足这个区间是一个 \(1\sim m\) 的排列. 数据 ...
- CF1157A-Reachable Numbers题解
原题地址 题目大意:有一个函数\(f(x)\),效果是将\(x+1\)后,去掉末尾所有的\(0\),例如: \(f(599)=6\),因为\(599+1=600→60→6\) \(f(7)=8\),因 ...
- CF359D:Pair of Numbers——题解
https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数 ...
- Timus : 1002. Phone Numbers 题解
把电话号码转换成为词典中能够记忆的的单词的组合,找到最短的组合. 我这道题应用到的知识点: 1 Trie数据结构 2 map的应用 3 动态规划法Word Break的知识 4 递归剪枝法 思路: 1 ...
随机推荐
- 浅谈java中的四个核心概念--思途青岛
Java已经成为一个庞大而复杂的技术平台,对于开发人员而言,要想更好的掌握Java技术,深入理解底层的技术处理细节必不可少. 现在介绍下java的四个核心概念: 1.Java虚拟机 Java虚拟机的主 ...
- 根据VCF构建进化树
VCF2Dis,是一款计算根据vcf文件计算距离矩阵的小工具 1 安装 下载后 tar -zxvf VCF2DisXXX.tar.gz cd VCF2DisXXX make # 添加环境变量即可 2 ...
- 毕业设计之zabbix+微信企业号报警
需要自己申请一个微信企业号 创建应用 AgentId 1000003 Secret SOI8b20G96yUVM29K02-bP5N5o6dovwSF2RrDaXHJNg 企业ID(自己再企业信息里面 ...
- Python压缩&解压缩
Python中常用的压缩模块有zipfile.tarfile.gzip 1.zipfile模块的简单使用 import zipfile # 压缩 z1 = zipfile.ZipFile('zip_t ...
- 【Redis】Sentinel 哨兵模式
Sentinel(哨兵模式) 目录 Sentinel(哨兵模式) 哨兵模式的三个定时任务 Sentinel(哨兵)与Sentinel .主服务器.从服务器之间的连接 检测下线状态 选择领头 Senti ...
- C#判断是否有中文
using System.Text.RegularExpressions; Regex reg = new Regex(@"[\u4e00-\u9fa5]"); if (reg.I ...
- C# CheckBoxList-DropDownList回显、筛选回显
<asp:CheckBoxList ID="ddlType" runat="server" RepeatColumns="10" Re ...
- LInkedList总结及部分底层源码分析
LInkedList总结及部分底层源码分析 1. LinkedList的实现与继承关系 继承:AbstractSequentialList 抽象类 实现:List 接口 实现:Deque 接口 实现: ...
- 【Go语言学习笔记】包
包其实是每个大型工程都会使用的模块化工具. 将相关的代码封装成一个包,给其他项目调用,提供不同的功能. GO的设计是将一个文件夹看成一个包,虽然不一定非要用文件夹的名字,但是比较建议. 同一个文件夹下 ...
- 02-爬取http://www.allitebooks.org/网站,获取图片url,书名,简介,作者
import requests from lxml import etree from bs4 import BeautifulSoup import json class BookSpider(ob ...