当前位置:网站首页>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;
}
边栏推荐
- Is it safe to open an account and buy stocks on the Internet? New to stocks, no guidance
- 安装gatewayworker之后启动start.php
- 银河麒麟系统局域网文件共享教程
- OpenSSL 编程 一:基本概念
- VMware vSphere esxi 7.0 installation tutorial
- What is a low code development platform? Why is it so hot now?
- MySQL performance optimization index function, hidden, prefix, hash index usage (2)
- Serveur mandataire SQUID
- 关于企业数字化的展望(38/100)
- 体验Navicat Premium 16,无限重置试用14天方法(附源码)
猜你喜欢

Flood fighting and disaster relief, overcoming difficulties, and City United premium products rushed to the aid of Yingde to donate loving materials

VMware vSphere esxi 7.0 installation tutorial

行业案例|从零售之王看银行数字化转型的运营之道

让马化腾失望了!Web3.0,毫无希望

非常全面的DolphinScheduler(海豚调度)安装使用文档

Implementation string mystring

华为伙伴暨开发者大会2022开源时刻全纪录

At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions

Graduation design of police report convenience service platform based on wechat applet

squid代理服务器
随机推荐
Focus! Tips for installing fonts on domestic computers
Day8 ---- 云资讯项目介绍与创建
At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
BTC和ETH重新夺回失地!引领市场复苏?加密将步入“冰河时代”!
1029 Median
于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日
GFS distributed file system
SQL必需掌握的100个重要知识点:使用函数处理数据
SQL必需掌握的100个重要知识点:排序检索数据
爱数课实验 | 第六期-金融反欺诈案例研究
DO280OpenShift访问控制--security policy和章节实验
通过CE修改器修改大型网络游戏
MYSQL 性能优化 index 函数,隐藏,前缀,hash 索引 使用方法(2)
Open a new ecological posture | use the wrodpress remote attachment to store it in COS
Is it safe to open an account and buy stocks? Who knows
爱数课实验 | 第七期-基于随机森林的金融危机分析
SQL server for circular usage
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?
JPA踩坑系列之save方法
Shell command used in actual work - sed