A - Mezo Playing Zoma
Today, Mezo is playing a game. Zoma, a character in that game, is initially at position x=0x=0. Mezo starts sending nn commands to Zoma. There are two possible commands:
- ‘L’ (Left) sets the position x:=x−1;
- ‘R’ (Right) sets the position x:=x+1.
Unfortunately, Mezo’s controller malfunctions sometimes. Some commands are sent successfully and some are ignored. If the command is ignored then the position xx doesn’t change and Mezo simply proceeds to the next command.
For example, if Mezo sends commands “LRLR”, then here are some possible outcomes (underlined commands are sent successfully):
- “LRLR” — Zoma moves to the left, to the right, to the left again and to the right for the final time,ending up at position 0;
- “LRLR” — Zoma recieves no commands, doesn’t move at all and ends up at position 0 as well;
- “LRLR” — Zoma moves to the left, then to the left again and ends up inposition -2.
Mezo doesn’t know which commands will be sent successfully beforehand. Thus, he wants to know how many different positions may Zoma end up at.
Input
The first line contains nn (1≤n≤105)(1≤n≤105) — the number of commands Mezo sends.The second line contains a string ss of nn commands, each either ‘L’ (Left) or ‘R’ (Right).
Output
Print one integer — the number of different positions Zoma may end up at.
Example
Input
4
LRLR
Output
5
Note
In the example, Zoma may end up anywhere between −2 and 2.
理解:
输入n个字母,只包括‘L’ ‘R’,分别表示向左和向右。每个字母都有可能有作用,也可能没作用,故最后至多有n+1个新位置(加上原来零点的位置。
#include<cstdio>
using namespace std;
int main()
{
int n;
char a[100010];
cin>>n;
cin>>a;
printf("%d",n+1);
return 0;
}
C - Fadi and LCM
Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a,b) such that LCM(a,b) equals X. Both a and b should be positive integers.
LCM(a,b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6,8)=24, LCM(4,12)=12, LCM(2,3)=6.
Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?
Input
The first and only line contains an integer X (1≤X≤10^12).
Output
Print two positive integers, aa and bb, such that the value of max(a,b) is minimum possible and LCM(a,b) equals X. If there are several possible such pairs, you can print any.
Examples
Input
2
Output
1 2
Input
6
Output
2 3
Input
4
Output
1 4
Input
1
Output
1 1
理解:
#include<cstdio>
#include<iostream>
#include<cmath>
typedef long long ll;
using namespace std;
ll gcd(ll a,ll b)
{
if(a%b==0)
return b;
else;
return gcd(b,a%b);
}
int main()
{
ll n;
cin>>n;
ll a=1,b=n;
for(ll i=1;i<sqrt(n);i++)
{
if(n%i==0)
{
b=n/i;
ll x=gcd(b,i);
if(x==1)
{
a=i;
continue;
}
}
}
cout<<a<<" "<<n/a;
return 0;
}
E - Deadline
Input
The first line contains a single integer T (1≤T≤50) — the number of test cases.The next TT lines contain test cases – one per line. Each line contains two integers nn and dd (1≤n≤1e9, 1≤d≤1e9 ) — the number of days before the deadline and the number of days the program runs.
Output
Print TT answers — one per test case. For each test case print YES (case insensitive) if Adilbek can fit in nn days or NO (case insensitive) otherwise.
Example
Input
3
1 1
4 5
5 11
Output
YES
YES
NO
题解:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int a,b,flag=0;
cin>>a>>b;
if(a>=b)
{
printf("YES\n");
continue;
}
int k=(a-1)/2;
if(b%(k+1)==0)
{
if((k+b/(k+1))<=a)
printf("YES\n");
else
printf("NO\n");
}
else
{
if((k+1+b/(k+1))<=a)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
F - Yet Another Meme Problem
Try guessing the statement from this picture http://tiny.cc/ogyoiz.
You are given two integers A and B, calculate the number of pairs (a,b) such that 1≤a≤A, 1≤b≤B, and the equation a⋅b+a+b=conc(a,b) is true; conc(a,b) is the concatenation of a and b (for example, conc(12,23)=1223, conc(100,11)=10011). a and b should not contain leading zeroes.
Input
The first line contains t (1≤t≤100) — the number of test cases.Each test case contains two integers A and B (1≤A,B≤109).
Output
Print one integer — the number of pairs (a,b) such that 1≤a≤A 1≤a≤A, and the equation a⋅b+a+b=conc(a,b) is true.
Example
Input
3
1 11
4 2
191 31415926
Output
1
0
1337
Note
There is only one suitable pair in the first test case: a=1, b=9 (1+9+1⋅9=19).
理解:
求有多少对(a,b)符合a⋅b+a+b=conc(a,b),1≤a≤A, 1≤b≤B,conc(a,b)=a10^n+b.(n为b的位数)
a⋅b+a+b=conc(a,b),则a⋅b+a+b=a10^n+b.(n为b的位数)
a⋅b+a=a10^n 则a(1+b)=a*10^n
b+1=10^n,只需要求出来在小于B范围内有多少符合这个条件的,再与A相乘即可。
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
int t;
cin>>t;
while(t--)
{
unsigned int A,B;//不能时int型 因为规定大于零(黑脸
cin>>A>>B;
ll k=B,count=0,n=1;
while(k)
{
k=k/10;
count++;
n*=10;
}//求出来B的位数
if((B+1)==n)//该数是否符合b+1=10^n,即最高位上的所以数是否有符合b+1=10^n的。
cout<<count*A<<endl;
else
cout<<(count-1)*A<<endl;
}
return 0;
}
G - HQ9+
HQ9+ is a joke programming language which has only four one-character instructions:
“H” prints “Hello, World!”,
“Q” prints the source code of the program itself,
“9” prints the lyrics of “99 Bottles of Beer” song,
“+” increments the value stored in the internal accumulator.
Instructions “H” and “Q” are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
Input
The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output
Output “YES”, if executing the program will produce any output, and “NO” otherwise.
Examples
Input
Hi!
Output
YES
Input
Codeforces
Output
NO
Note
In the first case the program contains only one instruction — “H”, which prints “Hello, World!”.In the second case none of the program characters are language instructions.
理解:
当输入的字符型中有’H’‘Q’'9’字符时,则有各自的输出,否则没有输出。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
char a[1000];
cin>>a;
int n=strlen(a);
for(int i=0;i<n;i++)
{
if(a[i]!='H'&&a[i]!='Q'&&a[i]!='9')
continue;
else
{
printf("YES");
return 0;
}
}
printf("NO");
return 0;
}