B.Phone Numbers

思路:就是简单的结构体排序,只是这里有一个技巧,就是结构体存储的时候,直接存各种类型的电话的数量是多少就行,在读入电话的时候,既然号码是一定的,那么就直接按照格式%c读取就好,在比较的时候也容易比较,直接比较ASCII码就行

代码:

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<cstdio>
  6. using namespace std;
  7. struct people{
  8. int num;
  9. char s[100];
  10. int t=0,p=0,c=0;
  11. }a[1500];
  12. bool cmpt(people a,people b){
  13. if(a.t==b.t){
  14. return a.num<b.num;
  15. }
  16. return a.t>b.t;
  17. }
  18. bool cmpp(people a,people b){
  19. if(a.p==b.p){
  20. return a.num<b.num;
  21. }
  22. return a.p>b.p;
  23. }
  24. bool cmpc(people a,people b){
  25. if(a.c==b.c){
  26. return a.num<b.num;
  27. }
  28. return a.c>b.c;
  29. }
  30. int main(){
  31. int t;
  32. scanf("%d",&t);
  33. for(int i=0;i<t;i++){
  34. a[i].num=i;
  35. int n;
  36. scanf("%d %s",&n,&a[i].s);
  37. int t=0;
  38. int p=0;
  39. int cc=0;
  40.  
  41. for(int j=0;j<n;j++){
  42. char b,c,d,e,f,g;
  43. char s;
  44. getchar();
  45. scanf("%c%c",&b,&c);
  46. scanf("%c",&s);
  47. scanf("%c%c",&d,&e);
  48. scanf("%c",&s);
  49. scanf("%c%c",&f,&g);
  50. if(b==c&&c==d&&d==e&&e==f&&f==g){
  51. t++;
  52. }else if(b>c&&c>d&&d>e&&e>f&&f>g){
  53. p++;
  54. }else{
  55. cc++;
  56. }
  57. }
  58. a[i].p=p;
  59. a[i].t=t;
  60. a[i].c=cc;
  61. }
  62. /*for(int i=0;i<t;i++){
  63. printf("%d %d %d\n",a[i].t,a[i].p,a[i].c);
  64. }*/
  65. int tt=0;
  66. int p=0;
  67. int c=0;
  68. int sump=0,sumt=0,sumc=0;
  69. sort(a,a+t,cmpt);
  70. tt=a[0].t;
  71. for(int i=0;i<t;i++){
  72. if(a[i].t==tt){
  73. sumt++;
  74. }
  75. }
  76. printf("If you want to call a taxi, you should call: ");
  77. for(int i=0;i<sumt;i++){
  78. printf("%s",a[i].s);
  79. if(i<sumt-1){
  80. printf(", ");
  81. }
  82. }
  83. printf(".\n");
  84. sort(a,a+t,cmpp);
  85. p=a[0].p;
  86. for(int i=0;i<t;i++){
  87. if(a[i].p==p){
  88. sump++;
  89. }
  90. }
  91. printf("If you want to order a pizza, you should call: ");
  92. for(int i=0;i<sump;i++){
  93. printf("%s",a[i].s);
  94. if(i<sump-1){
  95. printf(", ");
  96. }
  97. }
  98. printf(".\n");
  99. sort(a,a+t,cmpc);
  100. c=a[0].c;
  101. for(int i=0;i<t;i++){
  102. if(a[i].c==c){
  103. sumc++;
  104. }
  105. }
  106. printf("If you want to go to a cafe with a wonderful girl, you should call: ");
  107. for(int i=0;i<sumc;i++){
  108. printf("%s",a[i].s);
  109. if(i<sumc-1){
  110. printf(", ");
  111. }
  112. }
  113. printf(".");
  114. }

C.Win or Freeze

思路:其实最多两局,如果给定的这个数质因子大于2或者是质数,那么就是1赢,1直接选定两个质因子的乘积就能确保自己赢,剩下的情况就是2赢

代码:

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<cstdio>
  6. #include<vector>
  7. using namespace std;
  8. vector <pair<__int64, __int64> > divide(__int64 x) {
  9. vector <pair<__int64, __int64> > v;
  10. for (int i = 2; i <= x / i; ++i)
  11. if (x % i == 0) {
  12. int s = 0;
  13. while (x % i == 0) x /= i, s++;
  14. v.emplace_back(i, s);
  15. }
  16. if (x > 1) v.emplace_back(x, 1);
  17. return v;
  18. }
  19.  
  20. /*vector<__int64> get_divisors(__int64 x) {
  21. vector<__int64> res;
  22. for (__int64 i = 1; i <= x / i; ++i)
  23. if (x % i == 0) {
  24. res.push_back(i);
  25. if (i != x / i) res.push_back(x / i);
  26. }
  27. sort(res.begin(), res.end());
  28. return res;
  29. }*/
  30. inline bool isprime(long long n) {
  31. if (n < 2) return false;
  32. if (n == 2) return true;
  33. if (n % 2 == 0) return false;
  34. for (long long i = 3; i <= n / i; i += 2)
  35. if (n % i == 0) return false;
  36. return true;
  37. }
  38.  
  39. int main(){
  40. __int64 num;
  41. int flag=0;
  42. scanf("%I64d",&num);
  43. if(num==1){
  44. printf("1\n");
  45. printf("0\n");
  46. return 0;
  47. }else if(isprime(num)==true){
  48. printf("1\n");
  49. printf("0\n");
  50. return 0;
  51. }
  52. vector<pair<__int64,__int64>> v;
  53. v=divide(num);
  54. __int64 len=v.size();
  55. __int64 sum=0;
  56. __int64 sump=1;
  57. int f=0;
  58. for(__int64 i=0;i<len;i++){
  59. __int64 se=v.back().second;
  60. __int64 fi=v.back().first;
  61. v.pop_back();
  62. sum+=se;
  63. if(f<2){
  64. if(se>=2&&f==0){
  65. f++;
  66. f++;
  67. sump*=fi;
  68. sump*=fi;
  69. }else if(se<2){
  70. sump*=fi;
  71. f++;
  72. }else{
  73. sump*=fi;
  74. f++;
  75. }
  76. }
  77. }
  78. if(sum<=2){
  79. printf("2\n");
  80. }else{
  81. printf("1\n");
  82. printf("%I64d\n",sump);
  83. }
  84. }

D - Quantity of Strings

思路:主要分为k>n,k=n,k<n的情况,见代码,wa掉这么多主要是前两种考虑出了问题

代码:

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<cstdio>
  6. #include<vector>
  7. using namespace std;
  8. const long long int modd=1e9+7;
  9. int main(){
  10. int n,m,k;
  11. scanf("%d %d %d",&n,&m,&k);
  12. __int64 sum=0;
  13. if(k<n){
  14. if(k%2==0){
  15. sum+=m;
  16. /* if(k!=2){
  17. sum+=((m-1)*m)%modd;
  18. }*/
  19. }else{
  20. if(k==1){
  21. __int64 num=1;
  22. for(int i=0;i<n;i++){
  23. num=(num*m)%modd;
  24. num%=modd;
  25. }
  26. sum+=num;
  27. }else{
  28. __int64 num=1;
  29.  
  30. sum+=((m-1)*m)%modd;
  31.  
  32. sum+=m;
  33. }
  34. }
  35. }else if(k==n){
  36. if(k%2==0){
  37. __int64 num=1;
  38. for(int i=0;i<n/2;i++){
  39. num=(num*m)%modd;
  40. num%=modd;
  41. }
  42. sum+=num;
  43. }else{
  44. __int64 num=1;
  45. for(int i=0;i<(n/2)+1;i++){
  46. num=(num*m)%modd;
  47. num%=modd;
  48. }
  49. sum+=num;
  50. }
  51. }else{
  52. __int64 num=1;
  53. for(int i=0;i<n;i++){
  54. num=(num*m)%modd;
  55. num%=modd;
  56. }
  57. sum+=num;
  58. }
  59. printf("%I64d\n",sum);
  60. }

Codeforces Beta Round #107(Div2)的更多相关文章

  1. Codeforces Beta Round #73(Div2)

    A - Chord 题意:就是环中有12个字符,给你三个字符,判断他们之间的间隔,如果第一个和第二个间隔是3并且第二个和第三个间隔是4,那么就输出minor,如果第一个和第二个间隔是4并且第二个和第三 ...

  2. Codeforces Beta Round #94 div2 D 优先队列

    B. String time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  5. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  6. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  7. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  8. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  9. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

随机推荐

  1. 为 .NET 打 Call,为国产平台 Gitee 打 Call,我的 .NET/C# 开源项目清单,同步维护于 Github 和 Gitee

    所有项目遵循 MIT 开源协议.可以随意使用,但是需在源代码和产品关于画面保留版权声明和我的网站链接,谢谢. Sheng.Winform.IDE Github:https://github.com/i ...

  2. 050_Servlet详解

    目录 Servlet Servlet简介 HelloServlet Servlet原理 servlet-mapping Servlet请求路径 ServletContext Servlet上下文 Se ...

  3. mongodb安装及常见命令操作

    Mongodb是一个介于关系数据库和非关系数据库之间的产品(Nosql),是非关系数据库当中功能最丰富,最像关系数据库的,语法有点类似javascript面向对象的查询语言,它是一个面向集合的,模式自 ...

  4. POJ3278_Catch That Cow(JAVA语言)

    思路:bfs裸题.三个选择:向左一个单位,向右一个单位,向右到2*x //注意,需要特判n是否大于k,大于k时只能向左,输出n-k.第一次提交没注意,结果RE了,, Catch That Cow Ti ...

  5. maven-plugin-shade 详解

    一.介绍 [1] This plugin provides the capability to package the artifact in an uber-jar, including its d ...

  6. Alluxio+HDFS+MapReduce集成及测试

    目录 1.在 HDFS 上配置 Alluxio 1.1.节点角色 1.2.软件版本 1.3.准备工作 1.3.1.设置 SSH 免密登录 1.3.2.安装 JDK 1.3.3.安装 Hadoop 1. ...

  7. 更改当前目录--cd

    pwd   显示当前所在的目录路径 cd ../ 回到上一层目录 cd ../../     回到上上层目录 cd /          回到根目录 cd ~         回到当前用户的根目录 c ...

  8. [hash-bfs]USACO 3.2 Magic Squares 魔板

    魔 板 魔板 魔板 题目描述 在成功地发明了魔方之后,拉比克先生发明了它的二维版本,称作魔板.这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 5 我们知道魔板的每一个方格都有一种颜色 ...

  9. 【观隅】数据集管理与可视化平台-NABCD分析

    项目 内容 这个作业属于哪个课程 2021春季软件工程(罗杰 任健) 这个作业的要求在哪里 团队项目-初次邂逅,需求分析 项目介绍 观隅 数据集管理与可视化平台(取"观一隅而知全局" ...

  10. 铁人三项(第五赛区)_2018_seven

    铁人三项(第五赛区)_2018_seven 先来看看保护 保护全开,IDA分析 首先申请了mmap两个随机地址的空间,一个为rwx,一个为rw 读入的都shellcode长度小于等于7,且这7个字符不 ...