寒假集训1.30
Educational Codeforces Round 77 (Rated for Div. 2)
https://codeforces.com/contest/1260
A. Heating
思路
题意是给出ci个散热器,每个散热片由很多部分组成,给出每个房间需要的最小部分数sumi,每片散热器的代价为其部分数k的平方,求出满足最小部分的最小成本。
使用的散热器越多成本越低。
如果ci大于s等于umi,则每片散热器使用1部分即代价为sumi。
如果ci小于sumi,则使用ci个散热器均分sumi部分代价最低。
Code
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;
const int N=5007;
const ll mod=998244353;
int main(){
IO;
int t=1;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
if(n>=k){
cout<<k<<endl;
}
else{
int m=k/n;
int p=k%n;
int sum=0;
for (int i = 1; i <= n; ++i)
{
if(p){
p--;
sum+=(m+1)*(m+1);
}else sum+=m*m;
}cout<<sum<<endl;
}
}
return 0;
}
B - Obtain Two Zeroes
思路
题意为给出两个数a,b,你可以使用任意整数x使a变成a-x(或a-2·x),b变成b-2·x(或b-x)。
询问是否可以将a,b经过上述操作同时变成0。
考虑特殊值,当其中一个值为0时,如果另一个值不为0则无法进行操作,全为0时无需操作。
进行上述操作可看成将(a+b)每次减少3·x,如果可以达到要求则必须满足(a+b)%=0,需要特判一下假如2·a<b或者2·b<a时无法满足条件。
Code
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;
const int N=5007;
const ll mod=998244353;
int main(){
IO;
int t=1;
cin>>t;
while(t--){
int a,b;
cin>>a>>b;
if(min(a,b)==0){
if(max(a,b)!=0)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
continue;
}
if(2*min(a,b)<max(a,b)){
cout<<"NO"<<endl;continue;
}
if((a+b)%3)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return 0;
}
C - Infinite Fence
思路
当r=b时,因为k>=2,显然成立。
假设r>b,最大连续长度相当于长为r的区间内b的个数,与k进行比较即可。
- 当r=2·b时,最大连续长度为r/b-1,(0和r的倍数处染r)
- 当r!=2·b时,以r为长度的区间内b的个数以r和b的最小公倍数为最小单位进行循环,所以只需考虑r和b的最小公倍数内每个以r为长度的区间内b的最大个数即可,
因为lcm(r,b)=r·b/gcd(r,b),则共有b/gcd(r,b)个区间,一共有r/gcd(r,b)-1个b(起点和终点为r),b均分出现在每个区间中,所以最长长度为b的数量除以区间数,考虑是否整除的情况。
Code
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long ll;
const int N=1e5+7;
const ll mod=998244353;
ll gcd(ll x,ll y){
if(!y)return x;
else return gcd(y,x%y);
}
int main(){
IO;
int t=1;
cin>>t;
while(t--){
ll r,b,k;
cin>>r>>b>>k;
if(r==b){
cout<<"OBEY"<<endl;
continue;
}
if(r<b)swap(r,b);
if(r%b==0){
if(r/b-1>=k)cout<<"REBEL"<<endl;
else cout<<"OBEY"<<endl;
continue;
}
ll p=r*b/gcd(r,b);
ll m=b/gcd(r,b);
ll o=r/gcd(r,b)-1;
if(o/m+(o%m>0)>=k)cout<<"REBEL"<<endl;
else cout<<"OBEY"<<endl;
}
return 0;
}
Code will change the world !
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从零实现富文本编辑器#3-基于Delta的线性数据结构模型
· 记一次 .NET某旅行社酒店管理系统 卡死分析
· 长文讲解 MCP 和案例实战
· Hangfire Redis 实现秒级定时任务,使用 CQRS 实现动态执行代码
· Android编译时动态插入代码原理与实践
· 使用TypeScript开发微信小程序(云开发)-入门篇
· 没几个人需要了解的JDK知识,我却花了3天时间研究
· C#高性能开发之类型系统:从 C# 7.0 到 C# 14 的类型系统演进全景
· 管理100个小程序-很难吗
· 在SqlSugar的开发框架中增加对低代码EAV模型(实体-属性-值)的WebAPI实现支持