生活随笔
收集整理的這篇文章主要介紹了
Acwing第 36 场周赛【完结】
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
- 4215. 處理字符串
- 4216. 圖中的環(huán)【判環(huán)】
- 4217. 機器人移動【二分】
4215. 處理字符串
https://www.acwing.com/problem/content/4218/
#include<bits/stdc++.h>
#define YES puts("YES");
#define Yes puts("Yes");
#define yes puts("yes");
#define NO puts("NO");
#define No puts("No");
#define no puts("no");
using namespace std
;
typedef long long int LL
;
typedef pair
<int,int> PII
;
const int N
=1e5*2+10;
const int mod
=1e9+7;
int n
,m
,t
;
int a
[N
];
map
<char,int>mp
;
int main(void)
{string s
; cin
>>s
;string ans
;mp
['a']=1,mp
['e']=1,mp
['i']=1;mp
['o']=1,mp
['u']=1,mp
['y']=1;for(int i
=0;i
<s
.size();i
++){s
[i
]=tolower(s
[i
]);if(mp
[s
[i
]]) continue;ans
+='.';ans
+=s
[i
];}cout
<<ans
;return 0;
}
4216. 圖中的環(huán)【判環(huán)】
https://www.acwing.com/problem/content/4219/
#include<bits/stdc++.h>
using namespace std
;
const int N
=1e5+10;
int p
[N
],n
,m
;
int find(int x
)
{if(x
!=p
[x
]) p
[x
]=find(p
[x
]);return p
[x
];
}
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
;if(find(a
)==find(b
)) cnt
++;p
[find(a
)]=find(b
);}map
<int,int>mp
;for(int i
=1;i
<=n
;i
++) mp
[find(i
)]++;if(mp
.size()==1&&cnt
==1) puts("YES");else puts("NO");return 0;
}
4217. 機器人移動【二分】
https://www.acwing.com/problem/content/4220/
#include<bits/stdc++.h>
using namespace std
;
const int N
=1e5*2+10;
int U
[N
],D
[N
],L
[N
],R
[N
],n
,a
,b
;
string s
;
bool solve(int i
,int j
,int sum
)
{int u
=U
[i
-1]+U
[n
]-U
[j
];int d
=D
[i
-1]+D
[n
]-D
[j
];int l
=L
[i
-1]+L
[n
]-L
[j
];int r
=R
[i
-1]+R
[n
]-R
[j
];int x
=0,y
=0;y
+=u
,y
-=d
,x
-=l
,x
+=r
;sum
-=abs(x
-a
);sum
-=abs(y
-b
);if(sum
>=0&&sum
%2==0) return true;return false;
}
bool check(int len
)
{for(int i
=1;i
+len
-1<=n
;i
++){int j
=i
+len
-1;if(solve(i
,j
,len
)) return true;}return false;
}
int main(void)
{cin
>>n
>>s
>>a
>>b
;s
="0"+s
;for(int i
=1;i
<s
.size();i
++){U
[i
]=U
[i
-1],D
[i
]=D
[i
-1],L
[i
]=L
[i
-1],R
[i
]=R
[i
-1];if(s
[i
]=='U') U
[i
]++;if(s
[i
]=='D') D
[i
]++;if(s
[i
]=='L') L
[i
]++;if(s
[i
]=='R') R
[i
]++;}if(abs(a
)+abs(b
)>n
||(n
-abs(a
)-abs(b
))%2) {puts("-1");return 0;}int l
=0,r
=n
;while(l
<r
){int mid
=l
+r
>>1;if(check(mid
)) r
=mid
;else l
=mid
+1;}cout
<<l
<<endl
;return 0;
}
總結(jié)
以上是生活随笔為你收集整理的Acwing第 36 场周赛【完结】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。