当前位置:网站首页>Niuke white moon race 4 [solution]
Niuke white moon race 4 [solution]
2022-04-21 08:19:00 【Hui Xiaoge】
https://ac.nowcoder.com/acm/contest/134
This one is simpler than the last one .
Catalog
- triangle 【 thinking enumeration 】
- Game theory 【 Violence enumeration 】
- Bacterial infection 【 simulation 】
- Suburban spring outing 【floyd + DP】
- Floating point output 【 Sign in 】
- Equivalent string 【 thinking 】
- Black and white 【 simulation 】
- Adjacent candy 【 greedy 】
- Chorus formation 【 greedy 】
- Obsessive compulsive disorder 【 greedy 】
triangle 【 thinking enumeration 】

You'll find that , Since it's the longest . So these three sides must be connected together .
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long int LL;
typedef pair<int,int> pii;
LL n,m;
vector<pii>ve;
int main(void)
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
int x; cin>>x;
ve.push_back({
x,i+1});
}
sort(ve.begin(),ve.end());
while(m--)
{
int id; cin>>id;
LL a=0,b=0,c=0,flag=0;// Article 1 with a , Second , Article 3 the .
for(int i=n-1;i>=0;i--)
{
if(ve[i].second==id) continue;
c=b,b=a,a=ve[i].first;
if(a+b>c&&c!=0)// Satisfy triangle And all three sides have
{
flag=1;
break;
}
}
if(flag) cout<<a+b+c<<'\n';
else puts("-1");
}
return 0;
}
Game theory 【 Violence enumeration 】

#include<bits/stdc++.h>
using namespace std;
string s;
int main(void)
{
int n; cin>>n;
while(n--)
{
int x;cin>>x;
s+=to_string(x);
}
for(int i=0;i<=2000;i++)
{
string a=to_string(i);
if(s.find(a)==-1)
{
cout<<i;
break;
}
}
return 0;
}
Bacterial infection 【 simulation 】

#include<bits/stdc++.h>
using namespace std;
const int N=1010;
int st[N][N],n,m;
int dx[4]={
-1,0,0,1};
int dy[4]={
0,-1,1,0};
bool check(int x,int y)
{
int cnt=0;
for(int i=0;i<4;i++)
{
int tempx=x+dx[i],tempy=y+dy[i];
if(tempx<=0||tempx>n||tempy<=0||tempy>n) continue;
if(st[tempx][tempy]) cnt++;
}
return cnt>=2;
}
int main(void)
{
cin>>n>>m;
queue< pair<int,int> >q;
while(m--)
{
int x,y; cin>>x>>y;
q.push({
x,y});
st[x][y]=1;
}
while(q.size())
{
auto temp=q.front(); q.pop();
int x=temp.first,y=temp.second;
for(int i=0;i<4;i++)
{
int tempx=x+dx[i],tempy=y+dy[i];
if(tempx<=0||tempx>n||tempy<=0||tempy>n) continue;
if(st[tempx][tempy]) continue;
if(check(tempx,tempy)) q.push({
tempx,tempy}),st[tempx][tempy]=1;
}
}
bool flag=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++) if(!st[i][j]) flag=0;
if(flag) puts("YES");
else puts("NO");
return 0;
}
Suburban spring outing 【floyd + DP】
Floating point output 【 Sign in 】
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*2+10;
typedef long long int LL;
int main(void)
{
string s; cin>>s;
cout<<s;
return 0;
}
Equivalent string 【 thinking 】
Black and white 【 simulation 】
Adjacent candy 【 greedy 】

Chorus formation 【 greedy 】

First pretreatment , Compress , Will be adjacent to 1/0 Press together .
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
vector<pii>ve;
int n,cnt;
string s;
int main(void)
{
cin>>n>>s;
for(int i=0;i<s.size();i++)
{
int j=i;
while(j+1<s.size()&&s[j+1]==s[i]) j++;
ve.push_back({
s[i]-'0',j-i+1});
i=j;
}
for(int i=0;i<s.size();i++) if(s[i]=='0') cnt++;
int ans=0;
for(int i=0;i<ve.size();i++)
{
if(ve[i].first==0) ans=max(ans,ve[i].second);// yes 0
if(ve[i].first==1)// yes 1
{
if(ve[i].second==1)// only one
{
int temp=0;
if(i-1>=0&&ve[i-1].first==0) temp+=ve[i-1].second;
if(i+1<ve.size()&&ve[i+1].first==0) temp+=ve[i+1].second;
if(temp<cnt) ans=max(ans,temp+1);// You can exchange
}
else// Only in a certain period 0 After add 1 individual 0.
{
int temp=0;
if(i-1>=0&&ve[i-1].first==0) temp=max(temp,ve[i-1].second);
if(i+1<ve.size()&&ve[i+1].first==0) temp=max(temp,ve[i+1].second);
if(temp<cnt) ans=max(ans,temp+1);
}
}
}
cout<<ans<<endl;
return 0;
}
Obsessive compulsive disorder 【 greedy 】

Obviously, the least operand is the total number of numbers minus the total number of numbers . Because you can combine the repeated and the maximum number at a time . At this time, the quantity is less than 1.
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int n; cin>>n;
map<int,int>mp;
for(int i=0;i<n;i++)
{
int x; cin>>x;
mp[x]++;
}
cout<<n-mp.size()<<endl;
}
版权声明
本文为[Hui Xiaoge]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210742434722.html
边栏推荐
- Differences among directory, folder and file
- Express architecture in nodejs
- 将excel数据向数据库里导入时失败怎么解决
- 实现SPA实现单包授权技术的方案Fwknop
- [talkative cloud native] load balancing - the passenger flow of small restaurants has increased
- [template] optimized drawing of line segment tree
- 第五章 函数
- 一本快速入门ARM64体系结构的编程书
- MySQL的卸载安装与设置
- Multi classification logistic regression judgment of three classification iris
猜你喜欢
随机推荐
What is cross domain and how to solve cross domain problems
If ehcache is changed to redis cache according to the requirements, the detailed integration steps are as follows:
pydeck助数百万数据点高效可视化渲染
Prometheus 基础知识脑图
第六章 关联查询
给自己的网站添加一个可爱的妹子
Final Cut Pro 在视频的多个地方同时打马赛克
Ehcart map
实现SPA实现单包授权技术的方案Fwknop
js第十二篇
ESP32 VHCI实现BLE广播,就是这么神奇
解决数据库无法启动
WOS开道,微盟为中国SaaS趟新路
31 drop down box codes of provinces, municipalities and autonomous regions directly under the central government
类加载与类加载器概述
配置多个ssh-key
综合案例:品优购项目(品优购项目流程,SEO优化,TDK三大标签,代码)后期逐步优化
Xiaomi router 3G R3G brushes in the records of feed and openwrt 20.02.2
【大话云原生】负载均衡篇-小饭馆客流量变大了
将excel数据向数据库里导入时失败怎么解决









