当前位置:网站首页>Acwing game 59 [End]
Acwing game 59 [End]
2022-07-29 09:05:00 【Hui Xiaoge】
The difficulty of the topic is relatively simple , Mainly thinking questions .
https://www.acwing.com/activity/content/competition/problem_list/2015/
Catalog
4491. Array operation 【 thinking 】
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*10;
typedef long long int LL;
int a[N],s[N],temp,n;
int main(void)
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],s[i]=s[i-1]+a[i],temp=min(temp,s[i]);
cout<<s[n]-temp;
return 0;
}
4492. Subtraction operation 【 thinking 】

Prime number words , In one step . The number of times is divided by 2. In other cases, the factors are prime odd numbers .
So violent to find the smallest reduction , At this time, an odd number - An odd number . The result is even. The next step is directly in place .
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*10;
typedef long long int LL;
LL n,cnt;
void solve(LL n)
{
while(n)
{
if(n%2==0)
{
cnt+=n/2;
break;
}
for(LL i=3;i<=n;i+=2)
{
if(n%i==0)
{
cnt++;
n-=i;
break;
}
}
}
}
bool check(LL n)
{
if(n==1) return true;
for(LL i=2;i<=n/i;i++) if(n%i==0) return false;
return true;
}
int main(void)
{
cin>>n;
if(check(n)) cout<<1<<endl;
else solve(n),cout<<cnt<<endl;
return 0;
}
4493. Annular connected component 【 Find a clean ring 】

cf The original question of a certain time of , At that time, I forgot how to do . Another way of writing .
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*5+10;
int p[N],st[N],d[N],n,m;
int find(int x)
{
if(x!=p[x]) p[x]=find(p[x]);
return p[x];
}
vector< pair<int,int> >ve;
int main(void)
{
cin>>n>>m;
for(int i=1;i<=n;i++) p[i]=i;
int cnt=0;
while(m--)
{
int a,b; cin>>a>>b;
d[a]++,d[b]++;
ve.push_back({
a,b});
}
for(int i=1;i<=n;i++) if(d[i]>2) st[i]=1;// Marked as bad
for(int i=0;i<ve.size();i++)
{
int a=ve[i].first,b=ve[i].second;
if(find(a)==find(b)&&!st[find(a)]) cnt++;// It's a ring. And no redundant edges
else
{
if(st[find(a)]) st[find(b)]=1;// Merge good and bad before merging
p[find(a)]=find(b);
}
}
cout<<cnt;
return 0;
}
边栏推荐
- Is the sub database and sub table really suitable for your system? Talk about how to select sub databases, sub tables and newsql
- Compile and install Apache for rocky Foundation
- Amazfit dial Kit
- [unity entry program] collection of common learning websites
- Analysis of zorder sampling partition process in Hudi - "deepnova developer community"
- Tesseract图文识别--简单
- What is the difference between the pre training model and the traditional method in sorting?
- [C language] DataGridView binding data
- 2022 Teddy cup data mining challenge C project and post game summary
- Use disco diffusion to generate AI artwork in moment pool cloud
猜你喜欢

(视频+图文)机器学习入门系列-第2章 线性回归

Retinal Vessel Segmentation via a Semantics and Multi-Scale Aggregation Network

Introduction to translation professional qualification (level) examination

ERROR 1045 (28000): Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)

Flowable UI制作流程图

WQS binary learning notes

6.2 function-parameters

Information system project manager must recite the quality grade of the core examination site (53)

C # use database to bind listview control data

Tesseract图文识别--简单
随机推荐
01 knapsack about from two-dimensional optimization to one-dimensional optimization
Sudoku (DFS)
Asp graduation project - based on C # +asp Net+sqlserver laboratory reservation system design and Implementation (graduation thesis + program source code) - Laboratory Reservation System
Quick sorting (quick sorting) (implemented in C language)
数学建模——聚类
English high frequency suffix
Sublime text create page
Flowable 基础篇2
CVPR 2022 | clonedperson: building a large-scale virtual pedestrian data set of real wear and wear from a single photo
What are the backup and recovery methods of gbase 8s database
7.3-function-templates
预训练模型与传统方法在排序上有啥不同?
Data is the main body of future world development, and data security should be raised to the national strategic level
Error reporting when adding fields to sap se11 transparent table: structural changes at the field level (conversion table xxxxx)
What should I pay attention to now? Excuse me, is it safe to open a stock account by mobile phone?
2022 P cylinder filling test simulation 100 questions simulation test platform operation
md
Shutter gradient
Source code compilation pytorch pit
7.1-default-arguments