当前位置:网站首页>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 (●'◡'●)
边栏推荐
- . Net learning notes (V) -- lambda, LINQ, anonymous class (VaR), extension method
- Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
- [sword offer ii] sword finger offer II 029 Sorted circular linked list
- [LeetCode]513. Find the value in the lower left corner of the tree
- Null pointer exception
- Système de gestion - itclub (II)
- 洛谷P5706 再分肥宅水
- Process control task
- regular expression
- Bit. Store: long bear market, stable stacking products may become the main theme
猜你喜欢

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

Open source technology exchange - Introduction to Chengying, a one-stop fully automated operation and maintenance manager

win11桌面出现“了解此图片”如何删除

【MySQL】数据库函数通关教程下篇(窗口函数专题)

Go from introduction to actual combat -- channel closing and broadcasting (notes)

Set code exercise

管理系统-ITclub(中)

It smells good. Since I used Charles, Fiddler has been completely uninstalled by me
![[leetcode] dynamic programming solution partition array ii[arctic fox]](/img/a1/4644206db3e14c81f9f64e4da046bf.png)
[leetcode] dynamic programming solution partition array ii[arctic fox]

真香,自从用了Charles,Fiddler已经被我彻底卸载了
随机推荐
Analysis of stone merging
C语言程序设计详细版 (学习笔记1) 看完不懂,我也没办法。
win11桌面出现“了解此图片”如何删除
Method of reading file contents by Excel
How to do function test well? Are you sure you don't want to know?
石子合并问题分析
不外泄的测试用例设计秘籍--模块测试
Go from introduction to actual combat -- channel closing and broadcasting (notes)
Secret script of test case design without leakage -- module test
[LeetCode]513. Find the value in the lower left corner of the tree
登录凭证(cookie+session和Token令牌)
[LeetCode]508. 出现次数最多的子树元素和
.NET学习笔记(五)----Lambda、Linq、匿名类(var)、扩展方法
win11桌面出現“了解此圖片”如何删除
JVM memory structure when creating objects
Knowledge sorting of exception handling
Go from introduction to practice - polymorphism (note)
linux下安装oracle11g 静默安装教程
【Redis】零基础十分钟学会Redis
有时间看看ognl表达式