Codeforces Beta Round #107(Div2)
B - Phone Numbers
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.
Examples
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.
Note
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 2 taxi 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.
题意
一共有n个朋友,这几个朋友的通讯录中有几个电话号码(格式11-11-11)电话号码的根据以下规则有不同的含义:
1.taxi:如果电话号码全部数字相同如11-11-11,22-22-22…
2.pizza:如果电话号码严格递减如65-43-21…
3.girl:除去1,2两种情况其他的都为叫女孩子。
最后找出你的朋友中当你分别想做这三件事时你应该去找谁。
思路
模拟+暴力,建议使用结构体。
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
string name;
int taxi = 0;
int pizza = 0;
int girl = 0;
}n[101];
bool cmd1(node a,node b){
return a.taxi > b.taxi;
}
bool cmd2(node a,node b){
return a.pizza > b.pizza;
}
bool cmd3(node a,node b){
return a.girl > b.girl;
}
int t,m;
string f;
int a[7];
int main()
{
std::ios::sync_with_stdio(false);
string s;
int cnt = 0;
cin>>t;
int sum = t;
while(t--){
cin>>m;
cin>>f;
n[cnt].name = f;
for(int i = 0;i < m;i++){
cin>>s; //将电话的六位存储
a[0] = s[0] - '0';
a[1] = s[1] - '0';
a[2] = s[3] - '0';
a[3] = s[4] - '0';
a[4] = s[6] - '0';
a[5] = s[7] - '0';
if(a[0] == a[1] && a[1] == a[2] && a[2] == a[3] && a[3] == a[4] && a[4] == a[5])n[cnt].taxi++; //判断是否六位全相同
else if(a[0] > a[1] && a[1] > a[2] && a[2] > a[3] && a[3] > a[4] && a[4] > a[5])n[cnt].pizza++; //判断是否递减
else n[cnt].girl++;
}
cnt++;
}
/*string s1,s2,s3;
sort(n,n+sum,cmd1);
s1 = n[0].name;
sort(n,n+sum,cmd2);
s2 = n[0].name;
sort(n,n+sum,cmd3);
s3 = n[0].name;
cout<<s1<<endl;
cout<<s2<<endl;
cout<<s3<<endl;*/
int cnt1=0,cnt2=0,cnt3=0; //记录最大值有几个对于输出有帮助
int max1=-1,max2=-1,max3=-1; //记录最大值
for(int i = 0;i < sum;i++){
if(n[i].taxi > max1){
cnt1 = 1;
max1 = n[i].taxi;
}
else if(n[i].taxi == max1)cnt1++;
}
for(int i = 0;i < sum;i++){
if(n[i].pizza > max2){
cnt2 = 1;
max2 = n[i].pizza;
}
else if(n[i].pizza == max2)cnt2++;
}
for(int i = 0;i < sum;i++){
if(n[i].girl > max3){
cnt3 = 1;
max3 = n[i].girl;
}
else if(n[i].girl == max3)cnt3++;
}
cout<<"If you want to call a taxi, you should call:";
for(int i = 0;i < sum;i++){
if(n[i].taxi == max1 && cnt1 != 1){ //如果最大值不是最后一个,用','结尾
cout<<" "<<n[i].name<<",";
cnt1--;
}
else if(n[i].taxi == max1 && cnt1 == 1){ //如果是最后一个最大值用'.'结尾
cout<<" "<<n[i].name<<".";
cnt1--;
}
}
cout<<endl;
cout<<"If you want to order a pizza, you should call:";
for(int i = 0;i < sum;i++){
if(n[i].pizza == max2 && cnt2 != 1){
cout<<" "<<n[i].name<<",";
cnt2--;
}
else if(n[i].pizza == max2 && cnt2 == 1){
cout<<" "<<n[i].name<<".";
cnt2--;
}
}
cout<<endl;
cout<<"If you want to go to a cafe with a wonderful girl, you should call:";
for(int i = 0;i < sum;i++){
if(n[i].girl == max3 && cnt3 != 1){
cout<<" "<<n[i].name<<",";
cnt3--;
}
else if(n[i].girl == max3 && cnt3 == 1){
cout<<" "<<n[i].name<<".";
cnt3--;
}
}
cout<<endl;
}
C - Win or Freeze
You can’t possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number’s divisor is called non-trivial if it is different from one and from the divided number itself.
The first person who can’t make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move.
Input
The first line contains the only integer q (1 ≤ q ≤ 1013).
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Output
In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can’t even make the first move, print 0). If there are multiple solutions, print any of them.
Examples
Input
6
Output
2
Input
30
Output
1
6
Input
1
Output
1
0
Note
Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory.
题意
两个人分解数,对于一个数如果可以一步分成两个素数那么这个人就输出2,如果要分的数本身是素数或者1(特判)输出1,0。如果可以分出一个因子,该因子可以分成两个素数因子,则第一位玩家胜出,输出1,该因子。
思路
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e7+10;
int num[N] = {0};
ll q;
void primenum(ll s){
for(int i = 2;i <= sqrt(s);i++){
if(num[i] == 0){
for(int j = 2;j * i < sqrt(s);j++){
num[i*j]=1;
}
}
}
}
int isprime(ll s){
for(int i = 2; i <= sqrt(s);i++){
if(s % i == 0)return 0;
}
return 1;
}
int main(){
std::ios::sync_with_stdio(false);
cin>>q;
primenum(q);
ll num1,num2;
if(q == 1 || isprime(q)){
cout<<"1"<<endl;
cout<<"0"<<endl;
}
else{
for(int i = 2;i <= sqrt(q);i++){
if(q % i == 0 && num[i] == 0){
num1 = i;
num2 = q / i;
break;
}
}
if(isprime(num2)){
cout<<"2"<<endl;
}
else {
/*if(num2 < N){
}
else{}*/
for(int i = 2;i <= sqrt(num2);i++){
if(num2 % i == 0 && num[i] == 0){
num2 = i;
break;
}
}
cout<<"1"<<endl;
cout<<num1*num2<<endl;
}
}
}