AtCoder Beginner Contest 188

简介: A - Three-Point Shot

A - Three-Point Shot


题意: 输入两个分数求较低比高多3.


#include<bits/stdc++.h>
#define int long long
const int maxn=3e5+100;
int a[maxn];
using namespace std;
signed  main()
{
  int n,i,j,t;
  cin>>i>>j;
  int m1=min(i,j);
  if(m1+3>max(i,j))
    cout<<"Yes"<<endl;
  else 
    cout<<"No"<<endl;
}


B - Orthogonality


题意:求(A1B1)+…+(AnBn)是不是为0


#include<bits/stdc++.h>
#define int long long
const int maxn=3e5+100;
int a[maxn];
int b[maxn];
using namespace std;
signed  main()
{
  int sum=0;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    sum+=(a[i]*b[i]);
  }
  if(sum==0)
    cout<<"Yes"<<endl;
  else 
    cout<<"No"<<endl;
}


C - ABC Tournament


题意:给你2^n个数,两两相比,赢了的进下一轮,输了的被淘汰,求最后进入决赛被淘汰的人的位置。


思路:可以发现最后进入决赛的人就是前半边和后半边的最高分,所以比较两个输出分数低的那方。


#include<bits/stdc++.h>
using namespace std;
int a[65540];
int main()
{
  int i,j,n;
  cin>>n;
  int min1=-INT_MAX,min2=-INT_MAX,ans1=0,ans2=0;
  for(i=1;i<=pow(2,n);i++){
    cin>>a[i];
    if(i<=((pow(2,n))/2)){
      if(a[i]>min1)
        ans1=i,min1=a[i];
    }
    else {
      if(a[i]>min2)
        ans2=i,min2=a[i];
    }
  }
  if(min1>min2)
    cout<<ans2<<endl;
  else 
    cout<<ans1<<endl;
}


题意: 可以转化为在所给的区间里,每天活动所要消耗的c,求最小的SUMc,给你一个可以被消耗的Q能用来抵消当天的消耗。


思路:用差分然后放到map里,因为差分数组的前缀和就是当天的值,所以在和Q比较之后取较小的,再乘以几天就可以得到消耗的钱。


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
map<int, ll> mp;
int main(){
    ll i,n, c;
    cin >> n >> c;
    for( i = 1; i <= n; i ++){
        int  x, y, w;
        cin >> x >> y >> w;
        mp[x] += w; mp[y + 1] -= w;
    }
    ll s = 0, ans = 0;
    int last = 0;
    for(auto it : mp){
        ll x = min(s, c);
        ans += x * (it.first - last);
        s += it.second;
        last = it.first;
    }
    cout << ans << endl;
    return 0;
}



相关文章
|
算法
AtCoder Beginner Contest 213 E - Stronger Takahashi(01BFS)
AtCoder Beginner Contest 213 E - Stronger Takahashi(01BFS)
132 0
|
机器学习/深度学习 人工智能 Java
AtCoder Beginner Contest 215 D - Coprime 2 (质因子分解 gcd)
AtCoder Beginner Contest 215 D - Coprime 2 (质因子分解 gcd)
102 0
|
人工智能
atcoder AtCoder Beginner Contest 210 D - National Railway(dp)
atcoder AtCoder Beginner Contest 210 D - National Railway(dp)
114 0
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
AtCoder Beginner Contest 133 E - Virus Tree 2(组合数学)
100 0
|
机器学习/深度学习
AtCoder Beginner Contest 215 E - Chain Contestant (状压dp)
AtCoder Beginner Contest 215 E - Chain Contestant (状压dp)
117 0
|
机器学习/深度学习
AtCoder Beginner Contest 218 C - Shapes (模拟)
AtCoder Beginner Contest 218 C - Shapes (模拟)
142 0
AtCoder Beginner Contest 176 D - Wizard in Maze(01BFS)
AtCoder Beginner Contest 176 D - Wizard in Maze(01BFS)
113 0
AtCoder Beginner Contest 174 ——D.Alter Altar(思维)
AtCoder Beginner Contest 174 ——D.Alter Altar(思维)
88 0