题意:
给几个电话号码,其中,如果每个数字都相等,就是taxi的电话,如果每个数字递减,就是pizza的电话,其他全是girl的电话。然后按要求输出
思路:
开一个结构体,记录每个人的各自taxi,pizza,girl的电话数量,这题输出比较复杂,我们可以先把taxi,pizza,girl排序,让数量多的在前面,这样arr[0]就分别表示taxi,pizza,girl电话最多的人,如果数量相同,就把编号小的排在前面,因为输出的时候要先出现的人先输出,之后按要求模拟输出就可以
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <algorithm> 6 #include <cmath> 7 #include <queue> 8 #include <vector> 9 #include <map> 10 #include <set> 11 12 #define x first 13 #define y second 14 15 using namespace std; 16 17 typedef long long LL; 18 typedef pair<int, int>PII; 19 20 struct node 21 { 22 string name; 23 int id; 24 int t, p, g; 25 }arr[110]; 26 27 bool cmp_t(node x, node y) 28 { 29 if (x.t == y.t) return x.id < y.id; 30 return x.t > y.t; 31 } 32 33 bool cmp_p(node x, node y) 34 { 35 if (x.p == y.p) return x.id < y.id; 36 return x.p > y.p; 37 } 38 39 bool cmp_g(node x, node y) 40 { 41 if (x.g == y.g) return x.id < y.id; 42 return x.g > y.g; 43 } 44 45 int main() 46 { 47 int n; 48 cin >> n; 49 for (int i = 0; i < n; i++) 50 { 51 int m; 52 cin >> m >> arr[i].name; 53 arr[i].id = i; 54 for (int j = 0; j < m; j++) 55 { 56 int a, b, c; 57 scanf("%d-%d-%d", &a, &b, &c); 58 if (a % 10 == a / 10 && a == b && a == c) arr[i].t++; 59 else if (a / 10 > a % 10 && a % 10 > b / 10 && b / 10 > b % 10 && b % 10 > c / 10 && c / 10 > c % 10) arr[i].p++; 60 else arr[i].g++; 61 } 62 } 63 64 sort(arr, arr + n, cmp_t); 65 printf("If you want to call a taxi, you should call: "); 66 int first = 1;//记录第一次 67 for (int i = 0; i < n; i++) 68 { 69 if (arr[i].t != arr[0].t) break; 70 if (!first) cout << ", "; 71 cout << arr[i].name; 72 first = 0; 73 } 74 cout << "." << endl; 75 76 sort(arr, arr + n, cmp_p); 77 printf("If you want to order a pizza, you should call: "); 78 first = 1; 79 for (int i = 0; i < n; i++) 80 { 81 if (arr[i].p != arr[0].p) break; 82 if (!first) cout << ", "; 83 cout << arr[i].name; 84 first = 0; 85 } 86 cout << "." << endl; 87 88 sort(arr, arr + n, cmp_g); 89 printf("If you want to go to a cafe with a wonderful girl, you should call: "); 90 first = 1; 91 for (int i = 0; i < n; i++) 92 { 93 if (arr[i].g != arr[0].g) break; 94 if (!first) cout << ", "; 95 cout << arr[i].name; 96 first = 0; 97 } 98 cout << "." << endl; 99 100 return 0; 101 }
题意:
题目给了我们一个数,然后让两个人轮换操作:可以把这个数换成他的非平凡因数,如果那个人不能操作了,那么他就胜利。第一个人胜利,则输出它的第一场操作。每个人都希望自己胜利,也就是不会失误。
思路:(博弈)(质因数分解)
我们想要胜利,也就是想让自己不能操作,也就是如果我们制造出一个只有两个质因数的数,这样对手只能取走其中一个,那么我们走不动了,我们就赢了。所以我们面对一个数,我们的必败情况就是,它是由两个质数组成的。所以我们对n做质因数分解这个题就做完了。再看一眼数据范围,n可以等于1,所以加个特判。
质因数分解定理:任何大于1的数都可以拆分成素(质)数的乘积
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <algorithm> 6 #include <cmath> 7 #include <queue> 8 #include <vector> 9 #include <map> 10 #include <set> 11 12 #define x first 13 #define y second 14 15 using namespace std; 16 17 typedef long long LL; 18 typedef pair<int, int>PII; 19 20 const int N = 100010; 21 22 int zy[N]; 23 int cnt; 24 25 bool is_prime(LL x) 26 { 27 for (int i = 2; i <= sqrt(x); i++) 28 if (x % i == 0) return false; 29 return true; 30 } 31 32 void fenjie(LL x)//质因数分解 33 { 34 for (int i = 2; i <= sqrt(x); i++) 35 { 36 if (x % i == 0 && is_prime(i)) 37 { 38 while (x % i == 0) 39 { 40 zy[cnt++] = i; 41 x /= i; 42 } 43 } 44 } 45 if (x > 1) zy[cnt++] = x;//如果最后x没有除到1,说明最后x也是个质数 46 } 47 48 int main() 49 { 50 LL n; 51 cin >> n; 52 if (n == 1 || is_prime(n)) 53 { 54 cout << 1 << endl << 0 << endl; 55 return 0; 56 } 57 58 fenjie(n); 59 if (cnt == 2) 60 { 61 cout << 2 << endl; 62 } 63 64 else cout << 1 << endl << zy[0] * zy[1] << endl; 65 66 return 0; 67 }
题意:
定义一种字符串:长度为n,最多由m种字符组成,且其中任意长度为k的子串必须是回文串。那么这样的串你能构造出多少个呢?这个数可能很大,所以结果必须mod1000000007,小心不要遗漏任何字符串。
思路:
分类讨论:首先明确回文串这种东西奇数情况和偶数情况是显然要分类讨论的,所以要分k的奇偶,n是总长度肯定也要考虑,m是字符种类数,不过只是用来计算答案的,所以就不需要对m进行分类讨论了
注意有个坑在k > n的情况
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <algorithm> 6 #include <cmath> 7 #include <queue> 8 #include <vector> 9 #include <map> 10 #include <set> 11 12 #define x first 13 #define y second 14 15 using namespace std; 16 17 typedef long long LL; 18 typedef pair<int, int>PII; 19 20 const int MOD = 1e9 + 7; 21 22 LL quick_mod(LL a, LL b) 23 { 24 LL res = 1; 25 while (b) 26 { 27 if (b & 1) res = (res * a) % MOD; 28 b >>= 1; 29 a = (a * a) % MOD; 30 } 31 return res; 32 } 33 34 int main() 35 { 36 LL n, m, k; 37 cin >> n >> m >> k; 38 if (k > n) cout << quick_mod(m, n); 39 else if (k == n) cout << quick_mod(m, (n + 1) / 2); 40 else if (k == 1) cout << quick_mod(m, n); 41 else if (k % 2 == 0) cout << m << endl; 42 else cout << quick_mod(m, 2) << endl; 43 44 return 0; 45 }
原文:https://www.cnblogs.com/yctql/p/14777134.html