Atcoder Beginner Contest093小结

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 ab and c. Determine if S can be obtained by permuting abc.

Constraints

  • |S|=3
  • S consists of ab and c.

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

Copy
bac

Sample Output 1

Copy
Yes

Swapping the first and second characters in bac results in abc.


Sample Input 2

Copy
bab

Sample Output 2

Copy
No

Sample Input 3

Copy
abc

Sample Output 3

Copy
Yes

Sample Input 4

Copy
aaa

Sample Output 4

Copy
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

  • 1AB109
  • 1K100
  • 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

Copy
3 8 2

Sample Output 1

Copy
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

Copy
4 8 3

Sample Output 2

Copy
4
5
6
7
8

Sample Input 3

Copy
2 9 100

Sample Output 3

Copy
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 AB and C. Find the minimum number of operations required to make AB and C all equal by repeatedly performing the following two kinds of operations in any order:

  • Choose two among AB and C, then increase both by 1.
  • Choose one among AB and C, then increase it by 2.

It can be proved that we can always make AB and C all equal by repeatedly performing these operations.

Constraints

  • 0A,B,C50
  • 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 AB and C all equal.


Sample Input 1

Copy
2 5 4

Sample Output 1

Copy
2

We can make AB and C all equal by the following operations:

  • Increase A and C by 1. Now, ABC are 355, respectively.
  • Increase A by 2. Now, ABC are 555, respectively.

Sample Input 2

Copy
2 6 3

Sample Output 2

Copy
5

Sample Input 3

Copy
31 41 5

Sample Output 3

Copy
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

  • 1Q100
  • 1Ai,Bi109(1iQ)
  • 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

Copy
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

Sample Output 1

Copy
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;
}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值