B.Phone Numbers

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

代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;
struct people{
int num;
char s[100];
int t=0,p=0,c=0;
}a[1500];
bool cmpt(people a,people b){
if(a.t==b.t){
return a.num<b.num;
}
return a.t>b.t;
}
bool cmpp(people a,people b){
if(a.p==b.p){
return a.num<b.num;
}
return a.p>b.p;
}
bool cmpc(people a,people b){
if(a.c==b.c){
return a.num<b.num;
}
return a.c>b.c;
}
int main(){
int t;
scanf("%d",&t);
for(int i=0;i<t;i++){
a[i].num=i;
int n;
scanf("%d %s",&n,&a[i].s);
int t=0;
int p=0;
int cc=0; for(int j=0;j<n;j++){
char b,c,d,e,f,g;
char s;
getchar();
scanf("%c%c",&b,&c);
scanf("%c",&s);
scanf("%c%c",&d,&e);
scanf("%c",&s);
scanf("%c%c",&f,&g);
if(b==c&&c==d&&d==e&&e==f&&f==g){
t++;
}else if(b>c&&c>d&&d>e&&e>f&&f>g){
p++;
}else{
cc++;
}
}
a[i].p=p;
a[i].t=t;
a[i].c=cc;
}
/*for(int i=0;i<t;i++){
printf("%d %d %d\n",a[i].t,a[i].p,a[i].c);
}*/
int tt=0;
int p=0;
int c=0;
int sump=0,sumt=0,sumc=0;
sort(a,a+t,cmpt);
tt=a[0].t;
for(int i=0;i<t;i++){
if(a[i].t==tt){
sumt++;
}
}
printf("If you want to call a taxi, you should call: ");
for(int i=0;i<sumt;i++){
printf("%s",a[i].s);
if(i<sumt-1){
printf(", ");
}
}
printf(".\n");
sort(a,a+t,cmpp);
p=a[0].p;
for(int i=0;i<t;i++){
if(a[i].p==p){
sump++;
}
}
printf("If you want to order a pizza, you should call: ");
for(int i=0;i<sump;i++){
printf("%s",a[i].s);
if(i<sump-1){
printf(", ");
}
}
printf(".\n");
sort(a,a+t,cmpc);
c=a[0].c;
for(int i=0;i<t;i++){
if(a[i].c==c){
sumc++;
}
}
printf("If you want to go to a cafe with a wonderful girl, you should call: ");
for(int i=0;i<sumc;i++){
printf("%s",a[i].s);
if(i<sumc-1){
printf(", ");
}
}
printf(".");
}

C.Win or Freeze

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

代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
vector <pair<__int64, __int64> > divide(__int64 x) {
vector <pair<__int64, __int64> > v;
for (int i = 2; i <= x / i; ++i)
if (x % i == 0) {
int s = 0;
while (x % i == 0) x /= i, s++;
v.emplace_back(i, s);
}
if (x > 1) v.emplace_back(x, 1);
return v;
} /*vector<__int64> get_divisors(__int64 x) {
vector<__int64> res;
for (__int64 i = 1; i <= x / i; ++i)
if (x % i == 0) {
res.push_back(i);
if (i != x / i) res.push_back(x / i);
}
sort(res.begin(), res.end());
return res;
}*/
inline bool isprime(long long n) {
if (n < 2) return false;
if (n == 2) return true;
if (n % 2 == 0) return false;
for (long long i = 3; i <= n / i; i += 2)
if (n % i == 0) return false;
return true;
} int main(){
__int64 num;
int flag=0;
scanf("%I64d",&num);
if(num==1){
printf("1\n");
printf("0\n");
return 0;
}else if(isprime(num)==true){
printf("1\n");
printf("0\n");
return 0;
}
vector<pair<__int64,__int64>> v;
v=divide(num);
__int64 len=v.size();
__int64 sum=0;
__int64 sump=1;
int f=0;
for(__int64 i=0;i<len;i++){
__int64 se=v.back().second;
__int64 fi=v.back().first;
v.pop_back();
sum+=se;
if(f<2){
if(se>=2&&f==0){
f++;
f++;
sump*=fi;
sump*=fi;
}else if(se<2){
sump*=fi;
f++;
}else{
sump*=fi;
f++;
}
}
}
if(sum<=2){
printf("2\n");
}else{
printf("1\n");
printf("%I64d\n",sump);
}
}

D - Quantity of Strings

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

代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
const long long int modd=1e9+7;
int main(){
int n,m,k;
scanf("%d %d %d",&n,&m,&k);
__int64 sum=0;
if(k<n){
if(k%2==0){
sum+=m;
/* if(k!=2){
sum+=((m-1)*m)%modd;
}*/
}else{
if(k==1){
__int64 num=1;
for(int i=0;i<n;i++){
num=(num*m)%modd;
num%=modd;
}
sum+=num;
}else{
__int64 num=1; sum+=((m-1)*m)%modd; sum+=m;
}
}
}else if(k==n){
if(k%2==0){
__int64 num=1;
for(int i=0;i<n/2;i++){
num=(num*m)%modd;
num%=modd;
}
sum+=num;
}else{
__int64 num=1;
for(int i=0;i<(n/2)+1;i++){
num=(num*m)%modd;
num%=modd;
}
sum+=num;
}
}else{
__int64 num=1;
for(int i=0;i<n;i++){
num=(num*m)%modd;
num%=modd;
}
sum+=num;
}
printf("%I64d\n",sum);
}

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. VUE移动端音乐APP学习【四】:scroll组件及loading组件开发

    scroll组件 制作scroll 组件,然后嵌套一个 DOM 节点,使得该节点就能够滚动.该组件中需要引入 BetterScroll 插件. scroll.vue: <template> ...

  2. 数据库SQL查询作业

    --设有三个关系 --S(S#,SNAME,AGE,SEX) --SC(S#,C#,GRADE) --C(C#,CNAME,TEACHER) --(1)检索LIU老师所授课程的课程号.课程名 sele ...

  3. 妙味课上利用splice进行数组去重为什么要 j--

    var arr = [ 1,2,2,4,4,5,8,8,9,0,4,4 ]; for ( var i=0; i<arr.length; i++ ) { for ( var j=i+1; j< ...

  4. IDA报错fatal error before kernel init

    编写了一个IDA64插件,结果再打开IDA后报错fatal error before kernel init,然后闪退. 检查了一遍代码没发现有问题,后来发现是环境有一处配置错误, IDA64.exe ...

  5. c++ 反汇编 循环结构

    debug do···while 23: int nSum = 0; 00A572AE C7 45 F8 00 00 00 00 mov dword ptr [nSum],0 24: int nInd ...

  6. Activity类组成分析(一)Instrumentation

    目录 前言 解剖 继承关系 重要成员 Instrumentation 总结 前言 要了解清楚StartActivity的过程,Activity对象实例的构造过程是重要组成部分:而要弄清楚Activit ...

  7. 【C/C++】面相对象开发之封装

    封装继承多态是面向对象程序开发的基础概念.是实现面向对象的基本要素. 封装 程序开发,最核心价值,是数据. 程序其实是读取数据,操作数据,保存数据等一系列操作. 那么经过良好组织过的数据,将使编程事半 ...

  8. 201871030134-余宝鹏 实验三 结对项目—《D{0-1}KP 实例数据集算法实验平台》项目报告

    项目 内容 课程班级博客链接 班级博客 这个作业要求链接 作业要求 我的课程学习目标 1.体验软件项目开发中的两人合作,练习结对编程(Pair programming) 2.掌握GitHub协作开发程 ...

  9. php-mysql-防止sql注入

    1.防止sql注入-预准备 mysqli: $qSelect = $DBH->prepare("SELECT * FROM users WHERE username = ?" ...

  10. 【Azure Developer】使用Java代码启动Azure VM(虚拟机)

    问题描述 在使用Java的启动Azure VM的过程中,遇见了com.azure.core.management.exception.ManagementException: Status code ...