Codeforces Round #411 (Div. 2)(A,B,C,D 四水题)
A. Fake NP
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
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.
Input
The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).
Output
Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them.
Examples
Input
19 29
Output
2
Input
3 6
Output
3
Note
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代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 int l,r;
6 scanf("%d%d",&l,&r);
7 if(l==r)
8 cout<<l<<endl;
9 else cout<<2<<endl;
10 return 0;
11 }
B. 3-palindrome
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
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.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.
Output
Print the string that satisfies all the constraints.
If there are multiple answers, print any of them.
Examples
Input
2
Output
aa
Input
3
Output
bba
Note
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代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 int n;
6 while(scanf("%d",&n)!=EOF)
7 {
8 for(int i=1;i<=n;++i)
9 {
10 cout<<"a";
11 ++i;
12 if(i<=n)
13 cout<<"a";
14 ++i;
15 if(i<=n)
16 cout<<"b";
17 ++i;
18 if(i<=n)
19 cout<<"b";
20 }
21 cout<<endl;
22 }
23 return 0;
24 }
C. Find Amir
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
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.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of schools.
Output
Print single integer: the minimum cost of tickets needed to visit all schools.
Examples
Input
2
Output
0
Input
10
Output
4
Note
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代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 int n;
6 while(scanf("%d",&n)!=EOF)
7 {
8 int sum=n-1;
9 sum/=2;
10 printf("%dn",sum);
11 }
12 return 0;
13 }
D. Minimum number of steps
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
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.
Input
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Output
Print the minimum number of steps modulo 109 + 7.
Examples
Input
ab
Output
1
Input
aab
Output
3
Note
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的值再翻倍!
例如:
aab 遇到a变成 abba 遇到a变成bbbbaa b都是翻倍的增加的
下面给出AC代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 const int N=1e9+7;
4 int main()
5 {
6 string s;
7 cin>>s;
8 int ans=0;
9 int t=0;//b的数量
10 for(int i=s.length()-1;i>=0;i--)
11 {
12 if(s[i]=='b')
13 t=(t+1)%N;
14 else
15 {
16 ans=(ans+t)%N;
17 t=(t*2)%N;
18 }
19 }
20 cout<<ans<<endl;
21 return 0;
22 }
- 深度学习(deep learning)发展史
- 遗传算法简述
- Spark详解03Job 物理执行图Job 物理执行图
- 干货|Kotlin入门第一课:从对比Java开始
- Spark详解04Shuffle 过程Shuffle 过程
- Spark详解02Job 逻辑执行图Job 逻辑执行图
- Spark详解01概览|Spark部署|执行原理概览Job 例子
- Spark详解05架构Architecture架构
- SQL Server常用命令(平时不用别忘了)
- Spark详解06容错机制Cache 和 Checkpoint Cache 和 Checkpoint
- SQL Server 学习笔记
- Collaborative Filtering(协同过滤)算法详解
- 【Hadoop】三句话告诉你 mapreduce 中MAP进程的数量怎么控制?
- Spark系列课程-00xxSpark RDD持久化
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 【一天一大 lee】分割等和子集 (难度:中等) - Day20201011
- 【一天一大 lee】寻找两个正序数组的中位数 (难度:困难) - Day20201003
- 【一天一大 lee】颜色分类 (难度:中等) - Day20201007
- 【一天一大 lee】树中距离之和 (难度:困难) - Day20201006
- 在Spring项目中以多线程的方式并发执行,异步处理任务。解决统计、累加类业务的例子。
- 【十分钟教会你汇编】MIPS编程入门
- 实践中如何优化MySQL(收藏)
- Framework掌握不全被面试官怼?Android字节跳动大牛的精编解析笔记带你系统学习!
- 路由策略中的IP-Prefix你了解多少?
- 路由策略——Route-policy
- 如何合理设置线程池大小
- 前端设计模式之责任链模式
- 项目实战|基础请求封装
- 一种TreeView组件分页异步加载的方法
- V8 最佳实践:从 JavaScript 变量使用姿势说起