当前位置:网站首页>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 (●'◡'●)
边栏推荐
- C language programming detailed version (learning note 1) I can't understand it after reading, and I can't help it.
- [leetcode] dynamic programming solution partition array i[red fox]
- Golang uses regularity to match substring functions
- GBase 8a OLAP函数group by grouping sets的使用样例
- [MySQL] database function clearance Tutorial Part 2 (window function topic)
- Go from starting to Real - Interface (note)
- GBase 8a OLAP分析函数 cume_dist的使用样例
- Summary of gbase 8A database user password security related parameters
- 使用Fiddler模拟弱网测试(2G/3G)
- 百万年薪独家专访,开发人员不修复bug怎么办?
猜你喜欢
![[LeetCode]动态规划解分割数组I[Red Fox]](/img/b2/df87c3138c28e83a8a58f80b2938b8.png)
[LeetCode]动态规划解分割数组I[Red Fox]

百万年薪独家专访,开发人员不修复bug怎么办?

不外泄的测试用例设计秘籍--模块测试

Summary of Web testing and app testing by bat testing experts

Read write separation master-slave replication of MySQL

熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊

Go from introduction to actual combat -- channel closing and broadcasting (notes)
How to design an elegant caching function

Bit.Store:熊市漫漫,稳定Staking产品或成主旋律

读写分离-Mysql的主从复制
随机推荐
[leetcode] 508. Élément de sous - arbre le plus fréquent et
Special tutorial - Captain selection game
linux下安装oracle11g 静默安装教程
软件测试自动化测试之——接口测试从入门到精通,每天学习一点点
豆沙绿保护你的双眼
Bean paste green protects your eyes
Go from introduction to practice -- shared memory concurrency mechanism (notes)
Simulink method for exporting FMU model files
[sword offer ii] sword finger offer II 029 Sorted circular linked list
Test birds with an annual salary of 50w+ are using this: JMeter script development -- extension function
∫(0→1) ln(1+x) / (x ² + 1) dx
石子合并问题分析
Go from introduction to actual combat - execute only once (note)
IO stream code
[leetcode] dynamic programming solution split integer i[silver fox]
Little known MySQL import data
[LeetCode]161. Edit distance of 1
Golang uses regularity to match substring functions
GBase 8a OLAP分析函数cume_dist的使用样例
[LeetCode]508. 出现次数最多的子树元素和