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 ...
随机推荐
- Golang进阶,揉碎数据库中间件,干货满满!
目录 必读 一.Centos7.Mac安装MySQL 二.主从复制原理 2.1.基于binlog_filename + position 2.2.基于GTID 三.my.cnf 四.测试SQL 五.中 ...
- DVWA总结
Brute Force,即暴力(破解),是指黑客利用密码字典,使用穷举法猜解出用户口令,是现在最为广泛使用的攻击手法之一,如2014年轰动全国的12306"撞库"事件,实质就是暴力 ...
- Codeforces 356E - Xenia and String Problem(哈希)
Codeforces 题面传送门 & 洛谷题面传送门 首先显然一个 gray 串的长度只可能是 \(2^k-1\),其中 \(k\in\mathbb{Z}\). 考虑将一个字符改成另外一个字符 ...
- 洛谷 P7156 - [USACO20DEC] Cowmistry P(分类讨论+trie 树上 dp)
题面传送门 题意: 给出集合 \(S=[l_1,r_1]\cup[l_2,r_2]\cup[l_3,r_3]\cup\dots\cup[l_n,r_n]\) 和整数 \(k\),求有多少个三元组 \( ...
- Break up CF700C
Break up CF700C 首先考虑只能删一条边的做法,我们可以找出所有的桥,然后随便跑一条 S 到 T 路径,如果这条路径上有桥就说明可以,否则不行 发现这个做法其实是 O(M) 的 那么可以先 ...
- base64和图片转换
Base64是一种8Bit字节数据的编码方式. 在参数传输的过程中经常遇到的一种情况:使用全英文的没问题,但一旦涉及到中文就会出现乱码情况.与此类似,网络上传输的字符并不全是可打印的字符,比如二进制文 ...
- mVISTA 多序列比对叶绿体基因组
mVISTA可对2个或者多个DNA序列进行比较,可以对比对结果进行可视化. 详情请大力戳这里 0 输入文件说明 mVISTA 需要输入的文件有如下几类 必须文件 邮箱 fasta格式序列文件(或者GE ...
- R语言与医学统计图形-【18】ggplot2几何对象汇总
ggplot2绘图系统--几何对象汇总 前面介绍了常见的几种基本的几何对象,并且介绍了scale.stat等其他要素.后续将介绍position.themes.coord和faceting等函数. 这 ...
- error while loading shared libraries: libstdc++.so.5: wrong ELF class: ELFCLASS64
今天部署一个探针在运行的时候报了这样一个错:error while loading shared libraries: libstdc++.so.5: wrong ELF class: ELFCLAS ...
- PhantomJS的安装和使用
PhantomJS是一个无界面的.可脚本编程的WebKit浏览器引擎,它原生支持多种Web标准:DOM操作.CSS选择器.JSON.Canvas以及SVG.Selenium支持PhantomJS,这样 ...