当前位置:网站首页>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 (●'◡'●)
边栏推荐
- 软件测试自动化测试之——接口测试从入门到精通,每天学习一点点
- regular expression
- Knowledge sorting of exception handling
- Hash table - sum of arrays
- 大厂常用软件测试面试题三(附答案)
- Method of reading file contents by Excel
- TreeSet details
- Test birds with an annual salary of 50w+ are using this: JMeter script development -- extension function
- \W and [a-za-z0-9_], \Are D and [0-9] equivalent?
- Luogu p5706 redistributing fertilizer and house water
猜你喜欢

Use Fiddler to simulate weak network test (2g/3g)

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

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

Secret script of test case design without leakage -- module test

真香,自从用了Charles,Fiddler已经被我彻底卸载了

Exclusive interview with millions of annual salary. What should developers do if they don't fix bugs?

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

STM32CubeIDE1.9.0\STM32CubeMX 6.5 F429IGT6加LAN8720A,配置ETH+LWIP

美团20k软件测试工程师的经验分享

VMware virtual machine PE startup
随机推荐
\W and [a-za-z0-9_], \Are D and [0-9] equivalent?
Go from introduction to actual combat - execute only once (note)
.NET学习笔记(五)----Lambda、Linq、匿名类(var)、扩展方法
QT base64 encryption and decryption
Magic POI error in reading excel template file
[LeetCode]186. Flip word II in string
qt base64加解密
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
How to design an elegant caching function
GBase 8a OLAP函数group by grouping sets的使用样例
qt 大文件生成md5校验码
Little known MySQL import data
\w和[A-Za-z0-9_],\d和[0-9]等价吗?
How many ways does selenium upload files? I don't believe you have me all!
xpath
Go from introduction to actual combat - only any task is required to complete (notes)
【MySQL】数据库函数通关教程下篇(窗口函数专题)
Hash table - sum of arrays
如何做好功能测试?你确定不想知道吗?
Installing Oracle11g under Linux