Codeforces Round #411 (Div. 2)(A,B,C,D 四水题)
A. Fake NP
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve the problem to show that it's not a NP problem.
The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).
Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them.
19 29
2
3 6
3
Definition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
题目链接:http://codeforces.com/contest/805/problem/A
分析:直接判断l==r就输出l,否则输出2就可以了!
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int l,r;
scanf("%d%d",&l,&r);
if(l==r)
cout<<l<<endl;
else cout<<<<endl;
return ;
}
B. 3-palindrome
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
2
aa
3
bba
A palindrome is a sequence of characters which reads the same backward and forward.
题目链接:http://codeforces.com/contest/805/problem/B
分析:直接输出aabb.........这组样例即可,要多少个输出多少个,比如n=5 ,aabba,n=6,aabbaa。。。。。。
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;++i)
{
cout<<"a";
++i;
if(i<=n)
cout<<"a";
++i;
if(i<=n)
cout<<"b";
++i;
if(i<=n)
cout<<"b";
}
cout<<endl;
}
return ;
}
C. Find Amir
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.
There are n schools numerated from 1 to n. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools i and j costs and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school.
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of schools.
Print single integer: the minimum cost of tickets needed to visit all schools.
2
0
10
4
In the first example we can buy a ticket between the schools that costs .
题目链接:http://codeforces.com/contest/805/problem/C
分析: 就解释一下第二组数据怎么来的,即为答案!
1->10 ,10->2, 2->9, 9->3, 3->8 ,8->4,4->7,7->5,5->6
(1+10)%11==0;
(10+2)%11==1 ;
(2+9) %11==0;
(9+3)%11==1;
(3+8)%11==0;
(8+4)%11==1;
(4+7)%11==0;
(7+5)%11==1;
(5+6)%11==0;
上式求和sum即为4.。。。。。遍历一遍求值,即可
在探索的过程中,似乎发现了一个公式:sum=(n-1)/2;
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int sum=n-;
sum/=;
printf("%d\n",sum);
}
return ;
}
D. Minimum number of steps
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.
The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Print the minimum number of steps modulo 109 + 7.
ab
1
aab
3
The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa".
题目链接:http://codeforces.com/contest/805/problem/D
分析:用t去记录b得数量,遇到'b',t++,遇到'a'应该是先加上答案t的值,然后t的值再翻倍!
例如:
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
const int N=1e9+;
int main()
{
string s;
cin>>s;
int ans=;
int t=;//b的数量
for(int i=s.length()-;i>=;i--)
{
if(s[i]=='b')
t=(t+)%N;
else
{
ans=(ans+t)%N;
t=(t*)%N;
}
}
cout<<ans<<endl;
return ;
}
Codeforces Round #411 (Div. 2)(A,B,C,D 四水题)的更多相关文章
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade 水题
C. Efim and Strange Grade 题目连接: http://codeforces.com/contest/719/problem/C Description Efim just re ...
- Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题
A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Codeforces Round #373 (Div. 2) A. Vitya in the Countryside 水题
A. Vitya in the Countryside 题目连接: http://codeforces.com/contest/719/problem/A Description Every summ ...
- Codeforces Round #371 (Div. 2) A. Meeting of Old Friends 水题
A. Meeting of Old Friends 题目连接: http://codeforces.com/contest/714/problem/A Description Today an out ...
- Codeforces Round #355 (Div. 2) B. Vanya and Food Processor 水题
B. Vanya and Food Processor 题目连接: http://www.codeforces.com/contest/677/problem/B Description Vanya ...
- Codeforces Round #310 (Div. 2) B. Case of Fake Numbers 水题
B. Case of Fake Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题
B. Ohana Cleans Up Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/pr ...
- Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题
A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
随机推荐
- SQL Server-聚焦ROW_NUMBER VS TOP N性能
前言 抱歉各位,从八月份开始一直在着手写EntityFramework 6.x和EntityFramework Core 2.0的书籍写作,所以最近一直遗漏了对博客的管理,后面会着手于写SQL Ser ...
- HTTP协议------->资源和URL
1.前言 最近在研究http,希望结合书本,对网上资料进行整合,用“人话”聊聊这个玩意儿- 计划用近十篇文章,详尽的说清楚以下一些问题: URL和资源.HTTP报文是什么东西? HTTP是怎样进行链接 ...
- ionic环境配置及问题
ionic是什么? 其实就是一款用于开发web app的开源免费框架,和国产的MUI差不多. 官网:https://ionicframework.com/ 必备条件: 安装Node.js 安装Java ...
- Python3.5:装饰器的使用
在Python里面函数也是一个对象,而且函数对象可以被赋值给变量,所以,通过变量也能调用该函数,简单来说函数也是变量也可以作文函数的参数 >>> def funA(): ... pr ...
- Android中style和theme的区别
在学习Xamarin android的过程中,最先开始学习的还是熟练掌握android的六大布局-LinearLayout .RelativeLayout.TableLayout.FrameLayou ...
- Socket相关概念
lsocket的英文原义是“孔”或“插座”.作为进程通信机制,取后一种意思.通常也称作“套接字”,用于描述IP地址和端口,是一个通信链的句柄.(其实就是两个程序通信用的.) lsocket非常类似于电 ...
- MySQL主从复制原理以及架构
1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的 数据复制到其它主机(slaves)上,并 ...
- javascript中对象字面量与数组字面量
第一部分 我们知道JavaScript中的数据类型有基本数据类型和引用类型,其中Object类型就是非常常用的类型.那么如果创建一个Object类型的实例呢?下面我介绍两种方法: 第一:构造函数法. ...
- shell脚本的if语句,判断某程序是否存在,不存在启动该程序!
想必大家都知道 "如果......那么......" 这种语法的应用吧! 当然呢,linux下对于这种用法也是有所考虑的,很多时候我们都需要写一个shell脚本,难免会避免if语句 ...
- fastdfs集群
高可用的两大目的:数据备份,数据分片 1.FastDFS安装配置 先配置一台,将其中的配置文件打包,下载,然后配置其他机器时只需要解压即可, 打包命令 然后下载,上传到其他机器相对应的/etc目录下 ...