Codeforces Beta Round #107(Div2)
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)的更多相关文章
- Codeforces Beta Round #73(Div2)
A - Chord 题意:就是环中有12个字符,给你三个字符,判断他们之间的间隔,如果第一个和第二个间隔是3并且第二个和第三个间隔是4,那么就输出minor,如果第一个和第二个间隔是4并且第二个和第三 ...
- Codeforces Beta Round #94 div2 D 优先队列
B. String time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- 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]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
随机推荐
- 为 .NET 打 Call,为国产平台 Gitee 打 Call,我的 .NET/C# 开源项目清单,同步维护于 Github 和 Gitee
所有项目遵循 MIT 开源协议.可以随意使用,但是需在源代码和产品关于画面保留版权声明和我的网站链接,谢谢. Sheng.Winform.IDE Github:https://github.com/i ...
- 050_Servlet详解
目录 Servlet Servlet简介 HelloServlet Servlet原理 servlet-mapping Servlet请求路径 ServletContext Servlet上下文 Se ...
- mongodb安装及常见命令操作
Mongodb是一个介于关系数据库和非关系数据库之间的产品(Nosql),是非关系数据库当中功能最丰富,最像关系数据库的,语法有点类似javascript面向对象的查询语言,它是一个面向集合的,模式自 ...
- POJ3278_Catch That Cow(JAVA语言)
思路:bfs裸题.三个选择:向左一个单位,向右一个单位,向右到2*x //注意,需要特判n是否大于k,大于k时只能向左,输出n-k.第一次提交没注意,结果RE了,, Catch That Cow Ti ...
- maven-plugin-shade 详解
一.介绍 [1] This plugin provides the capability to package the artifact in an uber-jar, including its d ...
- 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. ...
- 更改当前目录--cd
pwd 显示当前所在的目录路径 cd ../ 回到上一层目录 cd ../../ 回到上上层目录 cd / 回到根目录 cd ~ 回到当前用户的根目录 c ...
- [hash-bfs]USACO 3.2 Magic Squares 魔板
魔 板 魔板 魔板 题目描述 在成功地发明了魔方之后,拉比克先生发明了它的二维版本,称作魔板.这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 5 我们知道魔板的每一个方格都有一种颜色 ...
- 【观隅】数据集管理与可视化平台-NABCD分析
项目 内容 这个作业属于哪个课程 2021春季软件工程(罗杰 任健) 这个作业的要求在哪里 团队项目-初次邂逅,需求分析 项目介绍 观隅 数据集管理与可视化平台(取"观一隅而知全局" ...
- 铁人三项(第五赛区)_2018_seven
铁人三项(第五赛区)_2018_seven 先来看看保护 保护全开,IDA分析 首先申请了mmap两个随机地址的空间,一个为rwx,一个为rw 读入的都shellcode长度小于等于7,且这7个字符不 ...