这应该是这个假期最后一次写博客了……
A题
Problem Statement
Given a positive integer N, find the maximum integer k such that .
Constraints
- N is an integer satisfying .
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer as an integer.
Sample 1
Input | Output |
---|---|
6 | 2 |
- k=2 satisfies .
- For every integer k such that holds.
Therefore, the answer is k=2.
Sample 2
Input | Output |
---|---|
1 | 0 |
Note that .
Sample 3
Input | Output |
---|---|
1000000000000000000 | 59 |
The input value may not fit into a 32-bit integer.
题目链接题解:
显然这道题不能用log函数做,就踏踏实实的用while循环解决吧。
AC代码:
#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <deque>
#include <set>
#define ll long long
#define PI acos(-1)
using namespace std;
const int N=2e5+5;
int a[N],b[N];
void solve()
{
ll n;
cin>>n;
int ans=0;
while (n)
{
n/=2;
ans++;
}
cout<<ans-1<<endl;
}
int main()
{
solve();
return 0;
}
B题
Problem Statement
Find the K-th lexicographically smallest string among the strings that are permutations of a string S.
What is a permutation of a string?
Constraints
- .
- S consists of lowercase English letters.
- There are at least K distinct strings that are permutations of S.
Input
Input is given from Standard Input in the following format:
S K
Output
Print the answer.
Sample 1
Input | Output |
---|---|
aab 2 | aba |
There are three permutations of a string aab
: { aab
, aba
, baa
}. The 2-nd lexicographically smallest of them is aba
.
Sample 2
Input | Output |
---|---|
baba 4 | baab |
Sample 3
Input | Output |
---|---|
ydxwacbz 40320 | zyxwdcba |
题解:
一道经典的全排列问题,只不过是字符串,本质是一样的。图个省事儿就直接拿stl中的next_permutation函数做就行。
AC代码:
#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <deque>
#include <set>
#define ll long long
#define PI acos(-1)
using namespace std;
void solve()
{
string s;
int k;
cin>>s>>k;
k--;
sort(s.begin(),s.end());
while (k)
{
next_permutation(s.begin(),s.end());
k--;
}
cout<<s<<endl;
}
int main()
{
solve();
return 0;
}
C题
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String t is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number x. Check if it's a quasi-palindromic number.
Input
The first line contains one integer number x (1 ≤ x ≤ ). This number is given without any leading zeroes.
Output
Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes).
Sample 1
Input | Output |
---|---|
131 | YES |
Sample 2
Input | Output |
---|---|
320 | NO |
Sample 3
Input | Output |
---|---|
2010200 | YES |
题解:
一道比较简单的字符串的问题,只需要在前面加几个前缀零或者删掉后面的后缀零再做回文判断就行,这里我采用加前缀零的方式判断。
题目链接AC代码:
#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <deque>
#include <set>
#include <iomanip>
#define ll long long
#define PI acos(-1)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
#define exp 1e-8
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+5;
int a[N],b[N];
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);
}
ll qpow(ll a,ll b)
{
ll f=1;
while (b)
{
if (b&1)
f=f*a;
a=a*a;
b>>=1;
}
return f;
}
void solve()
{
string s,ss;
cin>>s;
int i;
for (i=s.length()-1;i>=0;i--)
{
if (s[i]!='0')
break;
}
string t="";
for (int j=0;j<s.length()-1-i;j++)
t+="0";
s=t+s;
ss=s;
reverse(s.begin(),s.end());
if (s==ss)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
int main()
{
solve();
return 0;
}
D题
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful.
Therefore, Sasha decided to upsolve the following problem:
You have an array aa with nn integers. You need to count the number of funny pairs (l, r)(l≤r). To check if a pair (l, r) is a funny pair, take , then if r - l + 1 is an even number and al⊕al+1⊕…⊕amid=amid+1⊕amid+2⊕…⊕ar, then the pair is funny. In other words, ⊕ of elements of the left half of the subarray from l to r should be equal to ⊕ of elements of the right half. Note that ⊕ denotes the bitwise XOR operation.
It is time to continue solving the contest, so Sasha asked you to solve this task.
Input
The first line contains one integer n () — the size of the array.
The second line contains n integers a1,a2,…,an () — array itself.
Output
Print one integer — the number of funny pairs. You should consider only pairs where r−l+1 is even number.
Sample 1
Input | Output |
---|---|
5 1 2 3 4 5 | 1 |
Sample 2
Input | Output |
---|---|
6 3 2 2 3 7 6 | 3 |
Sample 3
Input | Output |
---|---|
3 42 4 2 | 0 |
Note
Be as cool as Sasha, upsolve problems!
In the first example, the only funny pair is (2, 5), as 2⊕3=4⊕5=1.
In the second example, funny pairs are (2, 3), (1, 4), and (3, 6).
In the third example, there are no funny pairs.
题解:
首先要明确一个定理:当两个数相等时,两个数的异或运算结果为零。利用这条结论,我们可以将所给的题目的区间条件合并起来,即找到一个区间[l, r] ,使得这段区间内所有数异或结果为零。所以我们拿前缀异或和维护原数组,并且r和l的奇偶性必须得不同,才能保证区间大小为偶数,所以分情况讨论,再累加结果就行。
AC代码:
#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <deque>
#include <set>
#include <iomanip>
#define ll long long
#define PI acos(-1)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
#define exp 1e-8
#define INF 0x3f3f3f3f
using namespace std;
const int N=3e6;
int a[N],b[N],c[N],d[N];
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);
}
ll qpow(ll a,ll b)
{
ll f=1;
while (b)
{
if (b&1)
f=f*a;
a=a*a;
b>>=1;
}
return f;
}
void solve()
{
int n;
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>a[i];
b[i]=b[i-1]^a[i];
}
ll ans=0;
for (int i=0;i<=n;i++)
{
if (i%2==0)
{
ans+=c[b[i]];
c[b[i]]++;
}
else if (i%2==1)
{
ans+=d[b[i]];
d[b[i]]++;
}
}
cout<<ans<<endl;
}
int main()
{
solve();
return 0;
}
E题
Problem Statement
You are given a person's systolic blood pressure, A, and diastolic blood pressure, B.
Find the mean arterial pressure, C, which we define as follows:
- C = .
Constraints
- 50≤B≤A≤300
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the value C.
Your output is considered correct when its absolute or relative error from our answer is at most .
Sample 1
Input | Output |
---|---|
130 100 | 110 |
We have C = .
Sample 2
Input | Output |
---|---|
300 50 | 133.3333333 |
Note that although all the values in input are integers, the value to output may not be an integer.
Sample 3
Input | Output |
---|---|
123 123 | 123 |
题解:
额……这题没啥可说的,注意精度就好了。
AC代码:
#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <deque>
#include <set>
#include <iomanip>
#define ll long long
#define PI acos(-1)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
#define exp 1e-8
#define INF 0x3f3f3f3f
using namespace std;
const int N=3e6;
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);
}
ll qpow(ll a,ll b)
{
ll f=1;
while (b)
{
if (b&1)
f=f*a;
a=a*a;
b>>=1;
}
return f;
}
void solve()
{
int a,b;
double c;
cin>>a>>b;
if ((a-b)%3==0)
cout<<(a-b)/3+b;
else
{
c=(double)(a-b)/3;
c+=b;
printf("%.6lf",c);
}
}
int main()
{
solve();
return 0;
}
F题
Problem Statement
You are given four strings S1, S2, S3, and S4.
Determine whether this sequence of strings has one of each of the following: H
, 2B
, 3B
, and HR
.
Here, it is guaranteed that every Si is H
, 2B
, 3B
, or HR
.
Constraints
- Each Si is
H
,2B
,3B
, orHR
.
Input
Input is given from Standard Input in the following format:
S1 S2 S3 S4
Output
If the given sequence of strings has one of each of H
, 2B
, 3B
, and HR
, print Yes
.
Otherwise, print No
.
Sample 1
Input | Output |
---|---|
3B HR 2B H | Yes |
We have one of each of H
, 2B
, 3B
, and HR
.
Sample 2
Input | Output |
---|---|
2B 3B HR 3B | No |
We have no H
.
题解:
额……这题没啥可说的,直接用set容器大小判断就行。
AC代码:
#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <deque>
#include <set>
#include <iomanip>
#define ll long long
#define PI acos(-1)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
#define exp 1e-8
#define INF 0x3f3f3f3f
using namespace std;
const int N=3e6;
ll gcd(ll a,ll b)
{
return b==0?a:gcd(b,a%b);
}
ll qpow(ll a,ll b)
{
ll f=1;
while (b)
{
if (b&1)
f=f*a;
a=a*a;
b>>=1;
}
return f;
}
void solve()
{
set<string> s;
for (int i=0;i<4;i++)
{
string t;
cin>>t;
s.insert(t);
}
if (s.size()!=4)
cout<<"No";
else
cout<<"Yes";
}
int main()
{
solve();
return 0;
}
ps:本人实力较菜,只能做出这些简单题,后面的题如果有哪位大神可以解决可以私信我,如果这里面有讲的不清楚或者有错误的,望及时指出!