当前位置:网站首页>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一起过(●'◡'●)
边栏推荐
猜你喜欢
MYSQL 性能优化 index 函数,隐藏,前缀,hash 索引 使用方法(2)
Release of global Unicorn list in 2021: the full list of 301 Unicorn enterprises in China is coming!
Show the comprehensive strength of strong products, and make the first show of 2022 Lincoln aviator in Southwest China
展现强劲产品综合实力 ,2022 款林肯飞行家Aviator西南首秀
划重点!国产电脑上安装字体小技巧
Covering access to 2w+ traffic monitoring equipment, EMQ creates a new digital engine for all elements of traffic in Shenzhen
Here are 12 commonly used function formulas for you. All used ones are good
Can Oracle's CTAs bring constraints and other attributes to the new table?
基于微信小程序的高校毕业论文管理系统#毕业设计
What is a low code development platform? Why is it so hot now?
随机推荐
Prospects for enterprise digitalization (38/100)
JPA踩坑系列之save方法
BTC and eth recapture the lost land! Leading the market recovery? Encryption will enter the "ice age"!
安全高效,非接触“刷手”身份识别助力疫情防控
UE4 essays: fstring, fname and ftext
Cerebral cortex: predicting children's mathematical skills from task state and resting state brain function connections
After kotlin wechat payment callback, the interface is stuck and uipagefragmentactivity windowleft is thrown
通过CE修改器修改大型网络游戏
分享一次自己定位 + 解决问题的经历
AI 绘画极简教程
分享|智慧环保-生态文明信息化解决方案(附PDF)
shell脚本控制服务的启动和关闭 - 具备详细案例
农产品期货怎么做怎么开户,期货开户手续费多少,找谁能优惠手续费?
Pycharm common functions - breakpoint debugging
白嫖红队goby&POC,叫你如何白嫖?
于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日
Abap-sm30 check before deletion
开启生态新姿势 | 使用 WrodPress 远程附件存储到 COS
分享下我是如何做笔记的
# Leetcode 821. Minimum distance of characters (simple)