当前位置:网站首页>Codeworks round 481 (Div. 3) [done]
Codeworks round 481 (Div. 3) [done]
2022-06-11 18:02:00 【Hui Xiaoge】
2022.3.1
Title address :https://codeforces.com/contest/978

Catalog
A. Remove Duplicates【 simulation 】

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],st[N],n;
set<int>s;
vector<int>ve;
int main(void)
{
cin>>n;
for(int i=0;i<n;i++) cin>>a[i],s.insert(a[i]);
cout<<s.size()<<endl;
for(int i=n-1;i>=0;i--)
{
if(st[a[i]]) continue;
ve.push_back(a[i]);
st[a[i]]++;
}
for(int i=ve.size()-1;i>=0;i--) cout<<ve[i]<<" ";
return 0;
}
B. File Name【 greedy / Double pointer 】

Work out paragraph by paragraph xxx…, Calculate the minimum number of deletions for each segment , Add it up .
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main(void)
{
cin>>n>>s;
if(s.find("xxx")==-1) puts("0");
else
{
int cnt=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='x')
{
int j=i;
while(j+1<s.size()&&s[j+1]=='x') j++;
int len=j-i+1;
if(len>=3) cnt+=len-2;
i=j;
}
}
cout<<cnt;
}
return 0;
}
C. Letters【 The prefix and + Two points 】

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N=1e5*2+10;
LL a[N],b[N],s[N],n,m;
int main(void)
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i],s[i]=s[i-1]+a[i];
for(int i=1;i<=m;i++)
{
cin>>b[i];
int index=lower_bound(s+1,s+n+1,b[i])-s;
cout<<index<<" "<<b[i]-s[index-1]<<endl;
}
return 0;
}
D. Almost Arithmetic Progression【 Violence enumeration 】

Not difficult, but there are many details , Enumerate the first two , The tolerance can be determined .
Then judge , Note that the maximum difference between the original data and the data of the arithmetic sequence is 1.
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*2+10;
typedef long long int LL;
int dx[3]={
0,-1,1};
int a[N],n,ans=1e9;
void solve(int x,int sum,int d)
{
int b[N]={
0};
b[1]=x;
for(int i=2;i<n;i++) b[i]=b[i-1]+d;// Construct an array based on prime tolerance
for(int i=2;i<n;i++)
{
int len=abs(b[i]-a[i]);
if(len>1) return;// Tolerance greater than 1
sum+=len;
}
if(sum<=n) ans=min(ans,sum);// The number of steps is less than or equal to n
}
int main(void)
{
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
if(n==1){
puts("0");return 0;}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
int tempx=a[0]+dx[i];
int tempy=a[1]+dx[j];
int d=tempy-tempx;// tolerance
solve(tempy,abs(dx[i])+abs(dx[j]),d);//a[1] They count tolerance
}
}
if(ans<=n) cout<<ans;
else cout<<-1;
return 0;
}
E. Bus Video System【 thinking greedy 】

Read the same question many times and you will find , The prefix sum is the number of people corresponding to each station .
Let's save ,minv and maxv Obviously, the problem is to shift the graph upward . How many steps can you pan at most to make minv>=0 And maxv<=m.
It is divided into 4 In this case :
- minv>=0,maxv>=0
- minv>=0,maxv<=0( direct pass)
- minv<=0,maxv>=0
- minv<=0,maxv<=0
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N],n,m;
int main(void)
{
cin>>n>>m;
int minv=1e9,maxv=-1e9,sum=0;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++)
{
sum+=a[i];
maxv=max(maxv,sum);
minv=min(minv,sum);
}
if(minv<-m||maxv>m)
{
puts("0");
return 0;
}
if(minv>=0&&maxv>=0) cout<<m-maxv+1;
else if(minv<=0&&maxv>=0)
{
maxv+=abs(minv);
if(maxv>m) puts("0");
else cout<<min(m-abs(minv)+1,m-maxv+1);
}
else if(minv<=0&&maxv<=0)
{
maxv+=abs(minv);
if(maxv>m) puts("0");
else cout<<min(m-abs(minv)+1,m-maxv+1);
}
return 0;
}
F. Mentors【 Two points 】

#include<bits/stdc++.h>
using namespace std;
const int N=1e5*2+10;
int a[N],b[N],cnt[N],n,m;
int main(void)
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i],b[i]=a[i];
sort(b+1,b+n+1);
while(m--)
{
int s1,s2; cin>>s1>>s2;
if(a[s1]>a[s2]) cnt[s1]--;// Subtract... From the number of conflicts
if(a[s1]<a[s2]) cnt[s2]--;// Subtract... From the number of conflicts
}
for(int i=1;i<=n;i++)
{
int l=lower_bound(b+1,b+n+1,a[i])-b;// Find greater than or equal to a[i] The subscript
if(b[l]>=a[i]) l--;// subtract
cnt[i]+=l;
cout<<cnt[i]<<" ";
}
return 0;
}
G. Petya’s Exams【 greedy 】

Sort by end first , In order of starting first .
Then enumerate the number of days , Greedy simulation can .
One thing to note is that the implied message of the title is , It is also common sense that every subject must be examined on the examination day .
#include<bits/stdc++.h>
using namespace std;
const int N=110;
int a[N],n,m,cnt,ans[N];
struct node{
int st,ed,c,k,id;}Node[N];
bool cmp(node a,node b)
{
if(a.ed==b.ed) return a.st<b.st;
return a.ed<b.ed;
}
int main(void)
{
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>Node[i].st>>Node[i].ed>>Node[i].c,Node[i].id=i+1;
}
sort(Node,Node+m,cmp);
for(int i=1;i<=n;i++)
{
for(int j=0;j<m;j++)
{
if((Node[j].c==Node[j].k)&&(i==Node[j].ed)) // Enough days to prepare , And it's exam day
{
ans[i]=m+1,cnt++;
break;
}
if(Node[j].k==Node[j].c) continue;// There are enough days to prepare, but it is not an exam day .
if(Node[j].st<=i&&i<Node[j].ed)// In the interval
{
ans[i]=Node[j].id;
Node[j].k++;
break;
}
}
}
if(cnt==m)// The test is over m door
{
for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
}else puts("-1");
return 0;
}
边栏推荐
- 6-7 file read / write operation
- adb 命令学习笔记
- System learning typescript (V) - joint type
- Can 400 fans earn 20W a month? How did you do it?
- Service学习笔记04- 其他服务实现方式与替代方式
- Getting started with Wireshark
- 送给大模型的「高考」卷:442人联名论文给大模型提出204个任务,谷歌领衔
- [pat grade B question bank] complete summary
- Test and analysis of tidb write hotspot
- Install MariaDB 10.5.7 (tar package installation)
猜你喜欢

Getting started with Wireshark

Chorus translation

【先收藏,早晚用得到】49个Flink高频面试题系列(一)

Initial experience of MariaDB spider sharding engine

The tle6389 step-down DC-DC switch controller has high efficiency in the whole load range of 1mA to 2.5A - keshijin mall

mysql8安装,navicat安装,sqli-labs搭建

Seeing the sudden death of a 28 year old employee, I was silent

Initial egg framework

Bracket generation ---2022/02/25

After class, I looked at the document and went back to the lab. I picked up the forgotten SQL operators again
随机推荐
[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (I)
【先收藏,早晚用得到】100个Flink高频面试题系列(三)
Delete the penultimate node of the linked list ---2022/02/22
Service learning notes 02- actual combat startservice and bindservice
【先收藏,早晚用得到】49个Flink高频面试题系列(二)
夜神安装apk,以及bp代理
mysql8安装,navicat安装,sqli-labs搭建
【深度学习基础】神经网络的学习(3)
聚类方法汇总
Learning about canvas API
开源项目那么多,这次带你了解个版本的区别,明白alpha版、beta版、rc版是什么意思
TestPattern error
Merge K ascending linked lists ---2022/02/26
6-3 读文章(*)
合并K个升序链表---2022/02/26
Using packstack to quickly install openstack
spawn ./ gradlew EACCES at Process. ChildProcess._ handle. onexit
Merge two ordered linked lists ---2022/02/24
Global and Chinese markets of solid polymer aluminum capacitors 2022-2028: Research Report on technology, participants, trends, market size and share
光纤熔接知识汇总【转载自微信公众号弱电智能化工程2018】