A - Three-Point Shot
Problem Statement
A basketball game is being played, and the score is now
X-Y. Here, it is guaranteed that X≠Y.
Can the team which is behind turn the tables with a successful three-point goal?
In other words, if the team which is behind earns three points, will its score become strictly greater than that of the other team?
Constraints
0≤X≤100
0≤Y≤100
X≠Y
X and Y are integers.
Sample Input 1
3 5
Sample Output 1
Yes
Sample Input 2
16 2
Sample Output 2
No
Sample Input 3
12 15
Sample Output 3
No
解题思路: 计算差是否小于3
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int N=300005;
typedef long long ll;
int main(){
int a,b;
cin>>a>>b;
int minn=min(a,b),maxn=max(a,b);
if(minn+3>maxn) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
B - Orthogonality
Problem Statement
Given are two N-dimensional vectors A=(A1,A2,A3,…,AN) and B=(B1,B2,B3,…,BN).
Determine whether the inner product of A and B is 0.
In other words, determine whether A1B1+A2B2+A3B3+⋯+ANBN=0.
Constraints
1≤N≤100000
−100≤Ai≤100
−100≤Bi≤100
All values in input are integers.
Sample Input 1
2
-3 6
4 2
Sample Output 1
Yes
The inner product of A and B is (−3)×4+6×2=0.
解题思路: 操作完观察是否为0。
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int N=300005;
int a[N],b[N];
typedef long long ll;
int main(){
ll n,sum=0;
cin>>n;
for(ll i=0;i<n;i++) cin>>a[i];
for(ll i=0;i<n;i++) cin>>b[i];
for(ll i=0;i<n;i++){
sum+=a[i]*b[i];
}
if(sum==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
C - ABC Tournament
Problem Statement
2N players, labeled 1 through 2N, will compete against each other in a single-elimination programming tournament.
The rating of Player i is Ai. Any two players have different ratings, and a match between two players always results in the victory of the player with the higher rating.
The tournament looks like a perfect binary tree.
Formally, the tournament will proceed as follows:
For each integer i=1,2,3,…,N in this order, the following happens.
For each integer j(1≤j≤2N−i), among the players who have never lost, the player with the (2j−1)-th smallest label and the player with the 2j-th smallest label play a match against each other.
Find the label of the player who will take second place, that is, lose in the final match.
Constraints
1≤N≤16
1≤Ai≤1e9
Ai are pairwise different.
All values in input are integers.
Sample Input
4
6 13 12 5 3 7 10 11 16 9 8 15 2 1 14 4
Sample Output
2
解题思路: 两两比较,大的数进入下一轮,最后比出第二名。
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
const int N=300005;
int a[N],b[N];
typedef long long ll;
int main(){
ll n,cnt=1;
ll minn;
cin>>n;
n=pow(2,n);
ll k=n;
for(ll i=1;i<=n;i++) cin>>a[i],b[i]=a[i];
if(n==2){
if(a[1]<a[2]) cout<<"1"<<endl;
else cout<<"2"<<endl;
return 0;
}
for(ll i=1;i<=n;i=i+2){
if(a[i]<a[i+1]) a[cnt++]=a[i+1];
else a[cnt++]=a[i];
if(i==n-1){
n/=2,cnt=1,i=-1;
if(n==2) break;
}
}
minn=min(a[1],a[2]);
for(ll i=1;i<=k;i++){
if(b[i]==minn){
cout<<i<<endl;
break;
}
}
return 0;
}