AtCoder Beginner Contest 093 2018/04/07 20:00:00 ~ 2018/04/07 21:40:00
呼呼(。-_-。)做了前三题,第四题突然变成700分,吓死我了
A - abc of ABC
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
You are given a string S of length 3 consisting of a
, b
and c
. Determine if S can be obtained by permuting abc
.
Constraints
- |S|=3
- S consists of
a
,b
andc
.
Input
Input is given from Standard Input in the following format:
S
Output
If S can be obtained by permuting abc
, print Yes
; otherwise, print No
.
Sample Input 1
bac
Sample Output 1
Yes
Swapping the first and second characters in bac
results in abc
.
Sample Input 2
bab
Sample Output 2
No
Sample Input 3
abc
Sample Output 3
Yes
Sample Input 4
aaa
Sample Output 4
No
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
string s;
cin>>s;
int f1=0,f2=0,f3=0;
for (int i=0;i<=s.size();i++)
{
if (s[i]=='a')
{
f1=1;
}
if (s[i]=='b')
{
f2=1;
}
if (s[i]=='c')
{
f3=1;
}
}
if (f1==1 && f2==1 && f3==1)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
return 0;
}
B - Small and Large Integers
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
Print all the integers that satisfies the following in ascending order:
- Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.
Constraints
- 1≤A≤B≤109
- 1≤K≤100
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B K
Output
Print all the integers that satisfies the condition above in ascending order.
Sample Input 1
3 8 2
Sample Output 1
3 4 7 8
- 3 is the first smallest integer among the integers between 3 and 8.
- 4 is the second smallest integer among the integers between 3 and 8.
- 7 is the second largest integer among the integers between 3 and 8.
- 8 is the first largest integer among the integers between 3 and 8.
Sample Input 2
4 8 3
Sample Output 2
4 5 6 7 8
Sample Input 3
2 9 100
Sample Output 3
2 3 4 5 6 7 8 9
题解:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
int a,b,k;
cin>>a>>b>>k;
int i;
for (i=a;i<=b;i++)
{
if (i-a<k || b-i<k)
{
cout<<i<<endl;
}
}
return 0;
}
C - Same Integers
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order:
- Choose two among A, B and C, then increase both by 1.
- Choose one among A, B and C, then increase it by 2.
It can be proved that we can always make A, B and C all equal by repeatedly performing these operations.
Constraints
- 0≤A,B,C≤50
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C
Output
Print the minimum number of operations required to make A, B and C all equal.
Sample Input 1
2 5 4
Sample Output 1
2
We can make A, B and C all equal by the following operations:
- Increase A and C by 1. Now, A, B, C are 3, 5, 5, respectively.
- Increase A by 2. Now, A, B, C are 5, 5, 5, respectively.
Sample Input 2
2 6 3
Sample Output 2
5
Sample Input 3
31 41 5
Sample Output 3
23
题解:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
int a[4];
cin>>a[1]>>a[2]>>a[3];
sort(a+1,a+4);
ll ans;
ans=(a[3]-a[1])/2+(a[3]-a[2])/2;
a[1]=a[3]-((a[3]-a[1])%2);
a[2]=a[3]-((a[3]-a[2])%2);
//cout<<a[1]<<" "<<a[2]<<" "<<a[3]<<endl<<ans;
if (a[1]==a[2])
{
if (a[3]-a[1]==1)
{
cout<<ans+1<<endl;
return 0;
}
else
{
cout<<ans<<endl;
return 0;
}
}
else
{
cout<<ans+2<<endl;
}
return 0;
}
D - Worst Case
Time limit : 2sec / Memory limit : 256MB
Score : 700 points
Problem Statement
101010 participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 101010-th.
The score of a participant is the product of his/her ranks in the two contests.
Process the following Q queries:
- In the i-th query, you are given two positive integers Ai and Bi. Assuming that Takahashi was ranked Ai-th in the first contest and Bi-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
Constraints
- 1≤Q≤100
- 1≤Ai,Bi≤109(1≤i≤Q)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Q A1 B1 : AQ BQ
Output
For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.
Sample Input 1
8 1 4 10 5 3 3 4 11 8 9 22 40 8 36 314159265 358979323
Sample Output 1
1 12 4 11 14 57 31 671644785
Let us denote a participant who was ranked x-th in the first contest and y-th in the second contest as (x,y).
In the first query, (2,1) is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print 1.
个人认为难爆了啊啊啊,考场WA了不知多少次:
#include <bits/stdc++.h>
using namespace std;
int64_t solution(int64_t a,int64_t b)
{
int64_t key,target=a*b;
for (int64_t i=sqrt(static_cast<long double>(target -1));i<std::max({a,b});++i)
{
if (target>i*i)
key=i;
else
break;
}
int64_t ans=2*key;
if (a<=key)
ans-=1;
if (b<=key)
ans-=1;
if (key*(key+1)>=target)
ans-=1;
return ans;
}
int main()
{
int q;
std::cin>>q;
for (int i=0;i<q;++i)
{
int64_t a,b;
std::cin>>a>>b;
std::cout<<solution(a,b)<<std::endl;
}
}