当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

2022 electrician (elementary) test question simulation test platform operation

【Unity入门计划】C#与Unity-了解类和对象

Error reporting when adding fields to sap se11 transparent table: structural changes at the field level (conversion table xxxxx)

Is the sub database and sub table really suitable for your system? Talk about how to select sub databases, sub tables and newsql

2022 R2 mobile pressure vessel filling test question simulation test platform operation

Flowable 基础篇1

Leetcode: interview question 08.14. Boolean operation

Mathematical modeling clustering

Using logistic regression and neural network to deal with complex binary classification problems

Asp graduation project - based on C # +asp Design and implementation of enterprise investment value analysis system based on. Net + sqlserver (graduation thesis + program source code) -- enterprise in
随机推荐
MySQL 错误总结
Cloud security daily 220712: the IBM integration bus integration solution has found a vulnerability in the execution of arbitrary code, which needs to be upgraded as soon as possible
6.3 references
Use disco diffusion to generate AI artwork in moment pool cloud
Unity3d learning notes (I)
Restful style details
不同数据库相同字段查不重复数据
Demonstration and solution of dirty reading, unrepeatable reading and unreal reading
2022 electrician (elementary) test question simulation test platform operation
状态压缩dp
[unity entry program] collection of common learning websites
Curl -v | JQ
Several ways of debugging support under oneos
【Unity入门计划】C#与Unity-了解类和对象
ICMP message analysis
数据表示与计算(进制)
LeetCode刷题(6)
6.2 function-parameters
Flowable 高级篇
C# 使用数据库对ListView控件数据绑定