A. Heating
题意:
由加热器。加热器有k个section。每个加热器的cost为
k
2
k^2
k2。
现在为每个房间配备加热器,使得每个房间至少拥有
s
u
m
i
sum_i
sumi个section。每个房间最多有
c
i
c_i
ci个加热器。
问:
每个房间的最少费用。
思路:
- 假如 c i > = s u m i c_i>=sum_i ci>=sumi,那么就说明,热水器够用cost为 s u m i sum_i sumi
- 假如不够,由于花费是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.
思路:
老套路了。(看代码即可)
反思:
- 本题特判。。。qwq。。。3wa。
- 还看错题。
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。
有四种染色方法:
- 在0,r,2r,3r。。。染红色
- 在0,b,2b,3b。。。染蓝色
- 在公倍数时,可以染任意颜色。
- 其他不染色。
现在按照顺序抽出被染色的。问是否有连续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;
}