当前位置:网站首页>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;
}
边栏推荐
- AI is at the forefront | focusing on natural language processing, machine learning and other fields; From Fudan University, Institute of automation, Chinese Academy of Sciences and other teams
- How does xjson implement four operations?
- How does xjson implement four operations?
- LeetCode刷题(6)
- [LOJ 6485] LJJ binomial theorem (unit root inversion) (template)
- RESTful 风格详解
- 7.3-function-templates
- [C language] DataGridView binding data
- Emmet syntax
- 【Unity入门计划】C#与Unity-了解类和对象
猜你喜欢

Leetcode:132. split palindrome string II

Mathematical modeling - Differential Equations

Asp graduation project - based on C # +asp Net+sqlserver laboratory reservation system design and Implementation (graduation thesis + program source code) - Laboratory Reservation System

Leetcode: interview question 08.14. Boolean operation

BI data analysis practitioners learn financial knowledge from scratch? What introductory books are recommended

7.2-function-overloading

Could not receive a message from the daemon

Requests library simple method usage notes

Gutcloud technology restcloud completed the pre-A round of financing of tens of millions of yuan

RESTful 风格详解
随机推荐
Floweable advanced
Information system project manager must recite the quality grade of the core examination site (53)
LeetCode刷题(6)
Using logistic regression and neural network to deal with complex binary classification problems
Transaction management in SQL Server
md
2022 electrician (elementary) test question simulation test platform operation
How does alternates achieve high-performance publish and subscribe?
Database system design: partition
Leetcode deduction topic summary (topic No.: 53, 3, 141, interview question 022, the entry node of the link in the sword finger offer chain, 20, 19, Niuke NC1, 103, 1143, Niuke 127)
What are the backup and recovery methods of gbase 8s database
Collation of ml.net related resources
Network knowledge summary
A little knowledge [synchronized]
6.3 references
C # use database to bind listview control data
7.2-function-overloading
Data is the main body of future world development, and data security should be raised to the national strategic level
C language -- 23 two-dimensional array
Leetcode question brushing (6)