当前位置:网站首页>Educational Codeforces Round 108 (Rated for Div. 2)
Educational Codeforces Round 108 (Rated for Div. 2)
2022-06-27 19:14:00 【我的故事用酒换】
2021.4.29
A
题意:有r个红豆角,b个蓝豆角,将这些豆角分组,要求每组两种豆角至少各有一个,并且每组豆角数量相差不超过d,判断分组是否可以成立。
题解:先取出k1=max(r,b)和k2=min(r,b),这样最多可以分成k2组,每组放一个,这样比它大的豆角最多可以取(d+1)*k2个,只需判断k1是否小于等于最大值就可以了。
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int main(void)
{
std::ios::sync_with_stdio(false);
ll t,r,b,d;
cin>>t;
while(t--)
{
cin>>r>>b>>d;
ll k=min(r,b);
ll maxx=(d+1)*k;
if(max(r,b)>maxx)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
return 0;
}
B
题意:走格子,每次只能向下走或者向右走一格,向下一步需要花费y,向右走需要花费x,就是走一步的花费就是横坐标或者纵坐标不变的那个,从点(1,1)花费k走到(n,m)是否成立?
题解:只需确定两个极值点,从点(1,1)走到(n,m)的最多花费和最小花费,最多花费就是横坐标或者纵坐标小的走到底,然后再往终点走去,最小花费则相反,最后判断k是否在这区间。
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
std::ios::sync_with_stdio(false);
int t,flag,n,m,k;
cin>>t;
while(t--)
{
flag=0;
cin>>n>>m>>k;
int maxx=max(n-1,m-1);
int minx=min(n-1,m-1);
int sum1=maxx+max(n,m)*(min(n,m)-1);
int sum2=minx+min(n,m)*(max(n,m)-1);
if(k>=sum2&&k<=sum1)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
C
题意:有编号1-n的学校,有n个选手,每个选手都有各自的能力值和其各自的学校,假设以k个人为一组,每个学校用能力值从大到小排组队,剩下组不成一队的就忽略掉,k
[1,n],输出所有学校队伍的能力值。
题解:将每个学校的队员进行排序,遍历1-n,将该学校所有以k人为一组的队员能力值加到对应的数组中,用前缀和比较快,最后输出所有加的数。
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int a[200005];
int main()
{
std::ios::sync_with_stdio(false);
ll t,n,x;
cin>>t;
while(t--)
{
cin>>n;
vector<ll>vis(n+1);
vector<ll>vc[n+1];
vector<ll>ans(n+1);
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
{
cin>>x;
vc[a[i]].push_back(x);
vis[a[i]]++;
}
for(int i=1;i<=n;i++)
{
sort(vc[i].begin(),vc[i].end());
for(int j=vis[i]-2;j>=0;j--)
vc[i][j]+=vc[i][j+1];
for(int j=1;j<=vis[i];j++)
ans[j-1]+=vc[i][vis[i]%j];
}
for(int i=0;i<n;i++)
cout<<ans[i]<<' ';
cout<<endl;
}
}D
题意:输入两个长度为n的序列a,b,可以选择序列a中最多一个长度小于等于n的子序列,将其顺序调换,求调换后
最大为多少?
题解:遍历每个点和以这个点为中心子序列的长度(子序列长度偶数另外看),依次往外扩展,若转换的子序列为[l,r],那么转换的子序列和就是转换子序列[l+1,r-1]的和加上
,然后加上前l-1和后r+1个未转换
的和,这个操作用前缀和比较快,这样遍历点和长度向外扩展时就可以比较转换后的最大值,然后取出最大值。
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;
int main(void)
{
std::ios::sync_with_stdio(false);
ll n;
cin>>n;
vector<ll>a(n+1),b(n+1),sum(n+1);
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>b[i];
for(int i=1;i<=n;i++)
sum[i]=sum[i-1]+a[i]*b[i];
ll maxx=sum[n],ans;
for(int i=1;i<=n;i++)
{
ans=a[i]*b[i];
for(int l=i-1,r=i+1;l>=1&&r<=n;l--,r++)
{
ans+=a[l]*b[r];
ans+=a[r]*b[l];
maxx=max(maxx,ans+sum[n]-sum[r]+sum[l-1]);
}
ans=0;
for(int l=i,r=i+1;l>=1&&r<=n;l--,r++)
{
ans+=a[l]*b[r];
ans+=a[r]*b[l];
maxx=max(maxx,ans+sum[n]-sum[r]+sum[l-1]);
}
}
cout<<maxx<<endl;
return 0;
}
边栏推荐
- Flood fighting and disaster relief, overcoming difficulties, and City United premium products rushed to the aid of Yingde to donate loving materials
- Modify large online games through CE modifier
- How to do a good job of gateway high availability protection in the big promotion scenario
- Codeforces Round #722 (Div. 2)
- 非常全面的DolphinScheduler(海豚调度)安装使用文档
- ICML2022 | 可扩展深度高斯马尔可夫随机场
- Codeforces Round #721 (Div. 2)
- BTC和ETH重新夺回失地!引领市场复苏?加密将步入“冰河时代”!
- 展现强劲产品综合实力 ,2022 款林肯飞行家Aviator西南首秀
- Unleash the innovative power of open source database | [Gansu] opengauss meetup has come to a successful conclusion
猜你喜欢

划重点!国产电脑上安装字体小技巧

数据平台调度升级改造 | 从Azkaban 平滑过度到Apache DolphinScheduler 的操作实践

JPA踩坑系列之save方法

No wonder people chose apifox instead of postman

BTC和ETH重新夺回失地!引领市场复苏?加密将步入“冰河时代”!

GFS分布式文件系统

Modify large online games through CE modifier

2021全球独角兽榜发布:中国301家独角兽企业全名单来了!

“好声音“连唱10年,星空华文如何唱响港交所?

Use the storcli tool to configure raid. Just collect this article
随机推荐
Ceph分布式存储
ARCS模型介绍
GFS distributed file system
Cerebral cortex: predicting children's mathematical skills from task state and resting state brain function connections
爱数课实验 | 第八期-新加坡房价预测模型构建
众昂矿业:新能源或成萤石最大应用领域
Day8 ---- 云资讯项目介绍与创建
GFS分布式文件系统
分享|智慧环保-生态文明信息化解决方案(附PDF)
Experience Navicat premium 16, unlimited reset, 14 day trial method (with source code)
This is the same as data collection. Can you define a parameter as last month or the previous day, and then use this parameter in SQL?
Necessary software tools in embedded software development
通过CE修改器修改大型网络游戏
Love math experiment | phase 9 - intelligent health diagnosis using machine learning method
Animal breeding production virtual simulation teaching system | Sinovel interactive
College graduation thesis management system based on wechat applet graduation design
华为伙伴暨开发者大会2022开源时刻全纪录
安全高效,非接触“刷手”身份识别助力疫情防控
308. 2D area and retrieval - variable segment tree / hash
VMware vSphere ESXi 7.0安装教程