当前位置:网站首页>Codeforces Round #723 (Div. 2)
Codeforces Round #723 (Div. 2)
2022-06-27 19:15:00 【我的故事用酒换】
2021.5.28
A
题意:输入一个2*n的序列a,a中每个元素不相等,要求对a进行重新组合形成序列b,使得b的每个元素不等于其两个邻居的中位数,即
,输出序列b
题解:只需先将序列a进行排序,然后将比较大的数插到小的数中间,这样可以保证每个数的邻居都是必这个元素大或者小,大的数从前面插还是从后面都是可以的,因为序列是偶数,可以保证前面那个条件。
#include <iostream>
#include <algorithm>
using namespace std;
const int N=105;
int a[N],b[N];
int main()
{
ios_base::sync_with_stdio(false);
int t,n;
cin>>t;
while(t--)
{
cin>>n;
n*=2;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
int l=0;
for(int i=0;i<n;i+=2)
{
b[i]=a[l++];
}
l=n-1;
for(int i=1;i<n;i+=2)
{
b[i]=a[l--];
}
for(int i=0;i<n;i++)
cout<<b[i]<<' ';
cout<<'\n';
}
return 0;
}
B
题意:输入一个x,判断x能否被11,111,…………相加得到,其中11这种元素可以取任意个
题解:只需枚举上述11这种元素的个数,然后判断能否等于x即可。因为偶数个1都可以整除11,所以遍历时只需枚举奇数个1,偶数个1取余11即可。
比赛时的代码(有一些不必要的):
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#define INF 111111
#define mod 998244353
#define ll long long
using namespace std;
const int N=105;
int main()
{
ios_base::sync_with_stdio(false);
ll t,n;
cin>>t;
while(t--)
{
cin>>n;
ll m=n%11;
int flag=0;
if(m)
{
for(int i=0;i<=m;i++)
{
for(int j=0;j<=m;j++)
{
for(int k=0;k<=m;k++)
{
ll sum=i*111+j*11111+k*1111111;
if(n>=sum&&i+j+k==m&&(n-sum)%11==0)
{
flag=1;
break;
}
}
if(flag)
break;
}
if(flag)
break;
}
}
else
flag=1;
if(flag)
cout<<"YES"<<'\n';
else
cout<<"NO"<<'\n';
}
return 0;
}赛后总结:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#define INF 111111
#define mod 998244353
#define ll long long
using namespace std;
const int N=105;
int main()
{
ios_base::sync_with_stdio(false);
ll t,n;
cin>>t;
while(t--)
{
cin>>n;
ll m=11;
int flag=0;
for(int i=0;i<=m;i++)
{
for(int j=0;j<=m;j++)
{
for(int k=0;k<=m;k++)
{
ll sum=i*111+j*11111+k*1111111;
if(n>=sum&&(n-sum)%11==0)
{
flag=1;
break;
}
}
if(flag)
break;
}
if(flag)
break;
}
if(flag)
cout<<"YES"<<'\n';
else
cout<<"NO"<<'\n';
}
return 0;
}
C1
C2
题意:输入一个长度为整数n的序列a,要求从序列里选择一些数从左往右加,每次累计加完的和不能为负数,输出选择的序列最长长度。
题解:用一个优先队列来维护加入的负数,如果加了一个负数使得累加和为负数,那么将这个负数加到队列里,然后去掉队列里一个最小的数,那么此刻的累加和=前面的累加和+加入负数和出队列的最小负数的差值,这样选择的序列长度不变,若加入的数不能使累加和变为负数则选择的数+1。
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2005;
ll dp[N][N],a[N];
int main()
{
ll n,sum=0,num=0;
cin>>n;
priority_queue <ll,vector<ll>,greater<ll> > q;
for(int i=1;i<=n;i++){
cin>>a[i];
sum+=a[i];
//cout<<sum<<endl;
if(a[i]<0)
{
q.push(a[i]);
}
if(sum<0)
{
ll k=q.top();
q.pop();
sum-=a[i];
sum+=(a[i]-k);
}
else
{
num++;
//cout<<a[i]<<endl;
}
//cout<<sum<<endl;
}
cout<<num<<endl;
return 0;
}写完C1发现自己的算法是O(n)的,所以C2一起过(●'◡'●)
边栏推荐
- Flask----应用案例
- Animal breeding production virtual simulation teaching system | Sinovel interactive
- GFS分布式文件系统
- 分享下我是如何做笔记的
- 抗洪救灾,共克时艰,城联优品驰援英德捐赠爱心物资
- 爱数课实验 | 第八期-新加坡房价预测模型构建
- 基于微信小程序的警局报案便民服务平台#毕业设计
- Shell script controls the startup and shutdown of services - with detailed cases
- AI 绘画极简教程
- Codeforces Round #721 (Div. 2)
猜你喜欢
![Unleash the innovative power of open source database | [Gansu] opengauss meetup has come to a successful conclusion](/img/21/9c5f5122270adea9444ff5f2d199ed.jpg)
Unleash the innovative power of open source database | [Gansu] opengauss meetup has come to a successful conclusion

SQL必需掌握的100个重要知识点:使用函数处理数据

Data platform scheduling upgrade and transformation | operation practice from Azkaban smooth transition to Apache dolphin scheduler

Openharmony hisysevent dotting and calling practice of # Summer Challenge (L2)

Sharing | intelligent environmental protection - ecological civilization informatization solution (PDF attached)

Industry case | see the operation of bank digital transformation from the king of retail

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

Character interception triplets of data warehouse: substrb, substr, substring

ICML2022 | 可扩展深度高斯马尔可夫随机场

SQL必需掌握的100个重要知识点:排序检索数据
随机推荐
Character interception triplets of data warehouse: substrb, substr, substring
KDD 2022 | 图“预训练、提示、微调”范式下的图神经网络泛化框架
MySQL usage notes 1
“好声音“连唱10年,星空华文如何唱响港交所?
VMware vSphere esxi 7.0 installation tutorial
Unity3d button adapts the size according to the text content
Best practice: optimizing Postgres query performance (Part 2)
"Good voice" has been singing for 10 years. How can the Chinese language in the starry sky sing well in HKEx?
Focus! Tips for installing fonts on domestic computers
SQL必需掌握的100个重要知识点:检索数据
分享|智慧环保-生态文明信息化解决方案(附PDF)
展现强劲产品综合实力 ,2022 款林肯飞行家Aviator西南首秀
Modify large online games through CE modifier
squid代理服務器
Release of global Unicorn list in 2021: the full list of 301 Unicorn enterprises in China is coming!
银河麒麟系统局域网文件共享教程
ABAP-CL_ OBJECT_ Collection tool class
系统自带的karsonzhang/fastadmin-addons报错
Ceph分布式存储
分享一次自己定位 + 解决问题的经历