AtCoder Beginner Contest 188
A Three-Point Shot
小于3则可以绝杀
#include <bits/stdc++.h>
#define int long long
using namespace std;
//const int mod = 998244353;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
void solve() {
int x,y;
cin>>x>>y;
if(abs(x-y)<3) cout<<"Yes";
else cout<<"No";
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--)
solve();
return 0;
}
B Orthogonality
#include <bits/stdc++.h>
#define int long long
using namespace std;
//const int mod = 998244353;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
int a[maxn],b[maxn];
void solve() {
int n;
cin>>n;
int sum=0;
for (int i = 0; i < n; ++i) {
cin>>a[i];
}
for (int j = 0; j < n; ++j) {
cin>>b[j];
sum+=a[j]*b[j];
}
if(sum==0) cout<<"Yes";
else cout<<"No";
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--)
solve();
return 0;
}
C ABC Tournament
从前一半和后一半找最大的在比较即可
#include <bits/stdc++.h>
#define int long long
using namespace std;
//const int mod = 998244353;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
void solve() {
int n;
cin>>n;
int premax=0;
int index1,index2;
for (int i = 1; i <=pow(2,n-1); ++i) {
int x;
cin>>x;
if(x>premax)
premax=x,index1=i;
}
int hmax=0;
for (int j = 1; j <=pow(2,n-1); ++j) {
int x;
cin>>x;
if(x>hmax)
hmax=x,index2=j+pow(2,n-1);
}
if(hmax>premax) cout<<index1;
else cout<<index2;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--)
solve();
return 0;
}
D - Snuke Prime
区间更新—差分
#include <bits/stdc++.h>
#define int long long
using namespace std;
//const int mod = 998244353;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
map<int ,int >mp;
void solve() {
int n,c;
cin>>n>>c;
for (int i = 0; i < n; ++i) {
int l,r,cc;
cin>>l>>r>>cc;
mp[l]+=cc,mp[r+1]-=cc;
}
int s=0;
int sum=0;
int now=0;
for(auto x:mp){
int pay=min(s,c);
sum+=pay*(x.first-now);
s+=x.second;
now=x.first;
}
cout<<sum;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--)
solve();
return 0;
}
F +1-1x2
记忆化搜索
#include <bits/stdc++.h>
#define int long long
using namespace std;
//const int mod = 998244353;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
map<int, int> mp;//记忆存储
int x, y;
//记忆化搜索
int dfs(int f) {
if (f <=x) return x-f;//x比y大只能减
if(mp[f]) return mp[f];
int step=f-x;//加法
step=min(step,dfs(f/2)+1+f%2);
if (f%2) step=min(step,dfs(f/2+1)+2);
return mp[f]=step;
}
void solve() {
cin >> x >> y;
cout << dfs(y);
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--)
solve();
return 0;
}