Educational Codeforces Round 77 (Rated for Div. 2)(A 数学||枚举 B 数学 C exgcd)

A. Heating

题意:

由加热器。加热器有k个section。每个加热器的cost为 k 2 k^2 k2
现在为每个房间配备加热器,使得每个房间至少拥有 s u m i sum_i sumi个section。每个房间最多有 c i c_i ci个加热器。

每个房间的最少费用。

思路:

  1. 假如 c i > = s u m i c_i>=sum_i ci>=sumi,那么就说明,热水器够用cost为 s u m i sum_i sumi
  2. 假如不够,由于花费是k^2,所以在可以满足条件下,的k1,和不可以满足条件的k2(k2=k1-1).枚举k1即可。

AC(枚举)

#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int tt;cin>>tt;
    while(tt--){
        ll c,sum;
        cin>>c>>sum;
        if(c>=sum)cout<<sum<<endl;
        else {
            ll a=sum/c,b;
            b=a+1;
            ll ans=8e18;
            for(ll i=0; i<=c; i++){
                ll num=i*a+(c-i)*b;
                ll tmp=i*a*a+(c-i)*b*b;
                if(num>=sum)ans=min(ans,tmp);
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}

AC(大佬的数学%%%%)

#include <bits/stdc++.h>
using namespace std;
void solve() {
    int c, sum;
    cin >> c >> sum;
    int x = sum / c;
    int c1 = sum - x * c;
    cout << c1 * (x + 1) * (x + 1) + (c - c1) * x * x << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

B. Obtain Two Zeroes

题意:

给你两个数,每次可以a-x,b-2x或者b-x,a-2x。

是否可以把a和b同时变为0.

思路:

老套路了。(看代码即可)

反思

  1. 本题特判。。。qwq。。。3wa。
  2. 还看错题。

AC

#include <iostream>
using namespace std;
int main()
{
    int tt;cin>>tt;
    while(tt--){
        int a,b;
        cin>>a>>b;
        if(a>b)swap(a,b);
        if(a==0&&b==0)cout<<"YES"<<endl;
        else if( (a+b)%3!=0 ||a==0|| b==0)cout<<"NO"<<endl;
        else if(a*2>=b)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

AC(大佬的%%%%)

#include <bits/stdc++.h>
using namespace std;
void solve() {
    int a, b;
    cin >> a >> b;
    cout << ((a + b) % 3 == 0 && max(a, b) <= 2 * min(a, b) ? "YES" : "NO") << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

C - Infinite Fence

题意:

给你r,b。
有四种染色方法:

  1. 在0,r,2r,3r。。。染红色
  2. 在0,b,2b,3b。。。染蓝色
  3. 在公倍数时,可以染任意颜色。
  4. 其他不染色。
    现在按照顺序抽出被染色的。问是否有连续k个是相同的颜色。

思路:

我不会证明。。。qwq
在这里插入图片描述
在这里插入图片描述

AC

#include <bits/stdc++.h>
using namespace std;
void solve() {
    int a, b, k;
    cin >> a >> b >> k;
    int g = __gcd(a, b);
    a /= g;
    b /= g;
    cout << (max(a, b) - 1 <= 1LL * min(a, b) * (k - 1) ? "OBEY" : "REBEL") << "\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值