当前位置:网站首页>Codeforces Round #723 (Div. 2)
Codeforces Round #723 (Div. 2)
2022-06-27 22:03:00 【My story was traded for wine】
2021.5.28
A
The question : Enter a 2*n Sequence a,a Each element in is not equal , Requirements for a Regroup to form a sequence b, bring b Each element of is not equal to the median of its two neighbors , namely
, Output sequence b
Answer key : Just put the sequence a Sort , Then insert the larger number in the middle of the smaller number , This can ensure that each number of neighbors must be larger or smaller than this element , Large numbers can be inserted from the front or from the back , Because the sequence is even , Can guarantee the previous condition .
#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
The question : Enter a x, Judge x Can be 11,111,………… Add up to get , among 11 This element can take any number
Answer key : Just enumerate the above 11 The number of such elements , Then judge whether it is equal to x that will do . Because even numbers 1 You can divide them all 11, So you only need to enumerate an odd number when traversing 1, Even number 1 Remainder 11 that will do .
Game code ( There are some unnecessary ):
#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;
}Summary after the game :
#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
The question : Enter an integer of length n Sequence a, It is required to select some numbers from the sequence and add them from left to right , The sum of each cumulative addition cannot be negative , Output the longest length of the selected sequence .
Answer key : A priority queue is used to maintain the added negative number , If you add a negative number to make the cumulative sum negative , Then add this negative number to the queue , Then remove the smallest number in the queue , Then the cumulative sum at this moment = The previous cumulative sum + The difference between the negative number added and the minimum negative number out of the queue , The length of the sequence thus selected remains the same , If the added number cannot make the cumulative sum negative, the selected number +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;
}finish writing sth. C1 Find your own algorithm is O(n) Of , therefore C2 Together (●'◡'●)
边栏推荐
- GBase 8a的create database 会被查询耗时很长怀疑卡住的现象分析
- Professor of Tsinghua University: software testing has gone into a misunderstanding - "code is necessary"
- 軟件測試自動化測試之——接口測試從入門到精通,每天學習一點點
- Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
- YOLOv6:又快又准的目标检测框架开源啦
- \w和[A-Za-z0-9_],\d和[0-9]等价吗?
- 开源技术交流丨一站式全自动化运维管家ChengYing入门介绍
- Bean paste green protects your eyes
- Method of reading file contents by Excel
- [LeetCode]30. 串联所有单词的子串
猜你喜欢

Simulink method for exporting FMU model files

It smells good. Since I used Charles, Fiddler has been completely uninstalled by me

AQS SOS AQS with me

【Redis】零基础十分钟学会Redis

Slow bear market, bit Store provides stable stacking products to help you cross the bull and bear

C language programming detailed version (learning note 1) I can't understand it after reading, and I can't help it.

This set of steps for performance testing using JMeter includes two salary increases and one promotion

List of language weaknesses --cwe, a website worth learning

语言弱点列表--CWE,一个值得学习的网站

∫(0→1) ln(1+x) / (x² + 1) dx
随机推荐
Figure countdownlatch and cyclicbarrier based on AQS queue
[LeetCode]508. 出现次数最多的子树元素和
[LeetCode]161. Edit distance of 1
如何做好功能测试?你确定不想知道吗?
Go from introduction to practice - error mechanism (note)
Null pointer exception
vmware虚拟机PE启动
[LeetCode]动态规划解拆分整数I[Silver Fox]
Gbase 8A OLAP analysis function cume_ Example of dist
xpath
Oracle migration MySQL unique index case insensitive don't be afraid
STM32CubeIDE1.9.0\STM32CubeMX 6.5 F429IGT6加LAN8720A,配置ETH+LWIP
[LeetCode]572. 另一棵树的子树
洛谷P5706 再分肥宅水
Go from introduction to actual combat - execute only once (note)
哈希表-数组之和
matlab查找某一行或者某一列在矩阵中的位置
[leetcode] dynamic programming solution split integer i[silver fox]
Interval DP of Changyou dynamic programming
[LeetCode]100. 相同的树