构造 Codeforces Round #107 (Div. 2) B. Phone Numbers

题目传送门

  1 /*
  2     构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:(
  3 */
  4 #include <cstdio>
  5 #include <algorithm>
  6 #include <cstring>
  7 #include <cmath>
  8 #include <vector>
  9 #include <map>
 10 #include <iostream>
 11 #include <string>
 12 using namespace std;
 13
 14 const int MAXN = 1e2 + 10;
 15 const int INF = 0x3f3f3f3f;
 16 struct Phone
 17 {
 18     string name;
 19     string num[MAXN];
 20     int tot, t, p, g, id;
 21 }p[MAXN];
 22
 23 bool cmp_t(Phone x, Phone y)
 24 {
 25     if (x.t == y.t)    return x.id < y.id;
 26     return x.t > y.t;
 27 }
 28
 29 bool cmp_p(Phone x, Phone y)
 30 {
 31     if (x.p == y.p)    return x.id < y.id;
 32     return x.p > y.p;
 33 }
 34
 35 bool cmp_g(Phone x, Phone y)
 36 {
 37     if (x.g == y.g)    return x.id < y.id;
 38     return x.g > y.g;
 39 }
 40
 41 int main(void)        //Codeforces Round #107 (Div. 2) B. Phone Numbers
 42 {
 43 //    freopen ("C.in", "r", stdin);
 44
 45     int n;
 46     while (cin >> n)
 47     {
 48         for (int i=1; i<=n; ++i)
 49         {
 50             cin >> p[i].tot >> p[i].name;    p[i].id = i;
 51             p[i].t = p[i].p = p[i].g = 0;
 52             for (int j=1; j<=p[i].tot; ++j)
 53             {
 54                 cin >> p[i].num[j];
 55                 if (p[i].num[j][0] == p[i].num[j][1] && p[i].num[j][1] == p[i].num[j][3] &&
 56                     p[i].num[j][3] == p[i].num[j][4] &&    p[i].num[j][4] == p[i].num[j][6] &&
 57                     p[i].num[j][6] == p[i].num[j][7])    p[i].t++;
 58                 else if (p[i].num[j][0] > p[i].num[j][1] && p[i].num[j][1] > p[i].num[j][3] &&
 59                         p[i].num[j][3] > p[i].num[j][4] && p[i].num[j][4] > p[i].num[j][6] &&
 60                         p[i].num[j][6] > p[i].num[j][7])    p[i].p++;
 61             }
 62             p[i].g = p[i].tot - p[i].t - p[i].p;
 63 //            cout << p[i].t << " " << p[i].p << " " << p[i].g << endl;
 64         }
 65
 66         int pre = 0;
 67         sort (p+1, p+1+n, cmp_t);
 68         cout << "If you want to call a taxi, you should call: ";
 69         for (int i=1; i<=n; ++i)
 70         {
 71             if (i == 1)
 72             {
 73                 cout << p[i].name;    pre = p[i].t;
 74             }
 75             else if (p[i].t == pre)    cout << ", " << p[i].name;
 76             else    break;
 77         }
 78         cout << "." << endl;
 79         sort (p+1, p+1+n, cmp_p);
 80         cout << "If you want to order a pizza, you should call: ";
 81         for (int i=1; i<=n; ++i)
 82         {
 83             if (i == 1)
 84             {
 85                 cout << p[i].name;    pre = p[i].p;
 86             }
 87             else if (p[i].p == pre)    cout << ", " << p[i].name;
 88             else    break;
 89         }
 90         cout << "." << endl;
 91         sort (p+1, p+1+n, cmp_g);
 92         cout << "If you want to go to a cafe with a wonderful girl, you should call: ";
 93         for (int i=1; i<=n; ++i)
 94         {
 95             if (i == 1)
 96             {
 97                 cout << p[i].name;    pre = p[i].g;
 98             }
 99             else if (p[i].g == pre)    cout << ", " << p[i].name;
100             else    break;
101         }
102         cout << "." << endl;
103     }
104
105     return 0;
106 }
107
108 /*
109 If you want to call a taxi, you should call: Rogulenko.
110 If you want to order a pizza, you should call: Fedorov, Rogulenko, Kaluzhin.
111 If you want to go to a cafe with a wonderful girl, you should call: Melnikov.
112 */
时间: 2024-10-06 01:38:24

构造 Codeforces Round #107 (Div. 2) B. Phone Numbers的相关文章

构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

题目传送门 1 /* 2 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 3 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况讨论一下 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-6 0:23:37 8 * File Name :B.cpp 9

暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

题目传送门 1 /* 2 题意:删除若干行,使得n行字符串成递增排序 3 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 4 */ 5 /************************************************ 6 Author :Running_Time 7 Created Time :2015-8-3 10:49:53 8 File Name :C.cpp 9 ************************************

贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

题目传送门 1 /* 2 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 3 */ 4 /************************************************ 5 Author :Running_Time 6 Created Time :2015-8-3 9:14:02 7 File Name :B.cpp 8 *************************************************/ 9 10 #include

构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

题目传送门 1 /* 2 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 3 构造:先求出使第1个指向0要多少步,按照这个次数之后的能否满足要求 4 题目读的好累:( 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <algorithm> 9 #include <cstring> 10 #i

构造 Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!

题目传送门 1 /* 2 构造:从大到小构造,每一次都把最后不是9的变为9,p - p MOD 10^k - 1,直到小于最小值. 3 另外,最多len-1次循环 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 typedef long long ll; 12 const i

Codeforces Round #107 (Div. 1) B. Quantity of Strings(推算)

http://codeforces.com/problemset/problem/150/B 题意: 给出n,m,k,n表示字符串的长度为n,m表示字符种类个数,k表示每k个数都必须是回文串,求满足要求的不同字符串有多少种. 思路:分奇偶推一下,当k为偶数时,容易发现如果n=k,那么有最多有k/2种不同的字符可填,如果n>k,你会发现此时所有位置都必须一样. 奇数的话会稍微麻烦一点,如果n=k,那么最多有k/2+1种不同的字符可填,如果n>k,你会发现此时最后只有2中不同的字符可填. 1 #i

Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造

Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/482/problem/A Description Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct posi

Codeforces Round #423 (Div. 2) C 思维,并查集 或 线段树 D 树构造,水

Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction   思维,并查集 或 线段树 题意:一个字符串被删除了,但给出 n条信息,要还原出可能的字典序最小的字符串.信息有:字符串ti,ki个位置xi,表明原本的字符串在xi位置是以字符串ti开头的. tags:惨遭 fst,一开始把所有字符串都存下来,排序做的,结果爆内存了.. 方法1: 考虑并查集,对于字符串 ti,在位置xi,

Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列其中相邻两项差的绝对值的个数(指绝对值不同的个数)为k个.求序列. 思路:1~k+1.构造序列前段,之后直接输出剩下的数.前面的构造可以根据,两项差的绝对值为1~k构造. AC代码: #include <stdio.h> #include <string.h> int ans[200010]; bool vis[100010]; i