当前位置:网站首页>Codeforces Round #799 (Div. 4)
Codeforces Round #799 (Div. 4)
2022-06-29 08:00:00 【Hunzi benhun】
List of articles
Codeforces Round #799 (Div. 4)
A. Marathon
The main idea of the topic
There are four people (a , b , c ,d) running , Ask how many people are a front
Code
int a[N] ;
bool cmp(int a , int b){
return a > b ;
}
void solve(){
int aa ;
for(int i = 1 ; i <= 4 ; i ++ ){
cin>>a[i];
if(i == 1 ) aa = a[i] ;
}
sort(a + 1 , a + 1 + 4 , cmp) ;
int res =0 ;
for(int i = 1 ; i <= 4 ; i ++){
if(a[i] == aa) break ;
res ++ ;
}
cout<<res<<"\n" ;
}
B. All Distinct
The question
n An array of lengths , You can delete two different locations , How long is the longest array left , Two are different
Ideas
Statistics delete a few , If you delete an even number , The answer is different numbers , If it's odd , The answer is different numbers - 1
Code
void solve(){
int n ;
read(n) ;
map<int , int> mp ;
for(int i = 1 ; i <= n ; i ++){
read(a[i]) ;
mp[a[i]] ++ ;
}
int s = n - mp.size() ;
int res = mp.size() ;
if(s % 2 )res -- ;
cout<<res <<"\n" ;
}
C. Where’s the Bishop?
The question
Each king can attack diagonals and diagonals , Ask the king where he is
Ideas
Check each position
Code
char a[10][10] ;
bool check(int x , int y){
if(a[x][y] != '#') return false ;
for(int i = 1 ; i <= 8 ; i ++ ) {
int xx = x + 1 , yy = y + 1 ;
if(xx <= 8 && yy <= 8) {
if(a[xx][yy] !='#') return false ;
}else break ;
}
for(int i = 1 ; i <= 8 ; i ++ ) {
int xx = x - 1 , yy = y - 1 ;
if(xx >=1 && yy >= 1) {
if(a[xx][yy] !='#') return false ;
}else break ;
}
for(int i = 1 ; i <= 8 ; i ++ ) {
int xx = x + 1 , yy = y - 1 ;
if(xx <= 8 && yy >= 1) {
if(a[xx][yy] !='#') return false ;
}else break ;
}
for(int i = 1 ; i <= 8 ; i ++ ) {
int xx = x - 1 , yy = y + 1 ;
if(xx >= 1 && yy <= 8) {
if(a[xx][yy] !='#') return false ;
}else break ;
}
return true;
}
void solve(){
for(int i = 1 ; i <= 8 ; i ++ ) {
for(int j = 1 ; j <= 8 ; j ++ ) {
cin>>a[i][j] ;
}
}
for(int i = 2 ; i <= 7 ; i ++ ){
for(int j = 2 ; j <= 7 ; j ++ ) {
if(check(i , j )) {
cout<<i <<" " <<j<<"\n" ;
return ;
}
}
}
}
D. The Clock
The question
At a given time , every other x Look at your watch every minute , How many palindromes can I see
Ideas
Initialize all times , Record the time you have seen , If you haven't seen it at the current time , Check whether it is a palindrome string , If you've seen it before , Jump out of
Code
vector<string>ve;
map<string , int> mp ;
int idx ;
void init() {
for(int i = 0 ; i <= 23 ; i ++ ) {
for(int j = 0 ; j <= 59 ; j ++ ) {
string str = "" ;
if(i < 10 ) str +='0' ,str +='0' + i ;
else str += i /10 + '0' , str += i % 10 + '0' ;
str +=':' ;
if(j < 10 ) str +='0' ,str +='0' + j ;
else str += j /10 + '0' , str += j % 10 + '0' ;
ve.pb(str) ;
mp[str] = ++idx ;
}
}
}
bool check(string str){
if(str[0] == str[4] && str[1] == str[3]) return true;
else return false ;
}
void solve(){
string str ;
int k ;
cin>>str >> k ;
int id = mp[str] - 1 ;
int res = 0 ;
map<int , int > ok;
while(true) {
if(ok[id]) break ;
else ok[id] = 1 ;
if(check(ve[id])) res ++ ;
id += k ;
id %= 1440 ;
}
cout<<res<<"\n" ;
}
signed main() {
init() ;
int t = 1 ;
read(t) ;
while(t -- ) solve() ;
return 0;
}
E. Binary Deque
The question
The length is n Array of , from 0 and 1 constitute , You can delete the first or last , Ask the least number of times , Make the total length of the array s
Ideas
Prefixes and records , Start from the first position , Half the maximum length , Finally, judge whether it is -1
Code
int a[N] , b[N] ;
void solve(){
int n , s ;
read(n) , read(s) ;
for(int i = 1 ; i <= n ; i ++ ) read(a[i]) ;
for(int i = 1 ; i <= n ; i ++ ) a[i] += a[i - 1];
int res = N ;
for(int i = 1 ; i <= n ; i ++ ) {
int l = i , r = n ;
while(l < r ){
int mid = l + r + 1 >> 1 ;
if(a[mid] - a[i - 1]<= s)l = mid;
else r = mid - 1 ;
}
if(a[l] - a[i - 1]== s) res = min(res , i - 1 + (n - l)) ;
}
if(res == N) res = -1 ;
cout<<res <<"\n" ;
}
F. 3SUM
The question
n An array of lengths , Whether there are three positions i, j , k , bring (ai + aj + ak) % 10 == 3
Ideas
The answer only relates to the single digits , Record the number of each number on your list , Again 1 0 3 10^3 103 Solve whether the conditions are met
Code
int a[N] , cnt[25];
void solve(){
int n ;
read(n) ;
map<int , int> mp ;
for(int i = 1 ; i <= n ; i ++ ){
read(a[i]) ;
a[i] = a[i] % 10 ;
mp[a[i]] ++ ;
}
for(int i = 0 ; i < 10 ; i ++ ) {
cnt[i] = mp[i] ;
}
for(int i = 0 ; i < 10 ; i ++ ) {
for(int j = 0 ; j < 10 ; j ++ ) {
for(int k = 0 ; k < 10 ; k ++ ) {
mp[i] -- ;
mp[j] -- ;
mp[k] -- ;
if(mp[i] >= 0 && mp[j] >= 0 && mp[k] >= 0 ) {
if((i + j + k) % 10 == 3) {
cout<<"YES\n" ;
return ;
}
}
mp[i] ++ ;
mp[j] ++ ;
mp[k] ++ ;
}
}
}
cout<<"NO\n" ;
}
G. 2^Sort
The question
Find subscript in [1 , n - k] There are several conditions 2 0 2^0 20 * ai < 2 1 2^1 21 * ai+1< 2 2 2^2 22 * ai+2< ⋯< 2 k 2^k 2k *ai+k.
Ideas
Prefixes and records , Whether the current Cheng Yu is greater than the previous one , Sweep it over , Judge whether the current interval is all satisfied
Code
int a[N] , ok[N];
void solve(){
int n , s ;
read(n) , read(s) ;
for(int i = 1 ; i <= n ; i ++ ) {
read(a[i]) ;
ok[i] = 0 ;
}
for(int i = 1 ; i < n ; i ++ ) {
if(a[i + 1 ] * 2 > a[i]) ok[i + 1 ] = 1 ;
}
for(int i = 2 ; i <= n ; i ++ ) ok[i] += ok[i - 1] ;
int res = 0 ;
for(int i = 1 ; i <= n - s ; i ++){
if(ok[i + s] - ok[i] == s ) {
res ++;
}
}
cout<<res <<"\n" ;
}
H. Gambling
The question
Given n An array of lengths , Ask for one a , l , r .a Is a number , l Is the table below the left section , r Is the subscript of the right interval . Conditions , The beginning is x = 1 , Start from the left section , identical x×=2 , Different x/=2 , requirement x Value is the largest
Ideas
Put the same values together , The current value is the previous bit and there are several differences between this bit *2 , Scan the maximum value , to update
Code
int a[N] ;
vector<int> ve[N] ;
void solve(){
int n ;
read(n) ;
int id = 0 ;
for(int i = 1 ; i <= n ; i ++ ) ve[i].clear() ;
map<int , int> mpid ;
map<int , int> mpnum ;
for(int i = 1 ; i <= n ; i ++ ) {
read(a[i]) ;
if(mpnum[a[i]] == 0 ) {
mpnum[a[i]] = ++ id ;
mpid[id] = a[i] ;
}
ve[mpnum[a[i]]].push_back(i) ;
}
int ansmaxx = 0 , l = -1 , r = -1 ,idans;
for(int i = 1 ; i <= id ; i ++ ) {
vector<int> all ;
all.push_back(0) ;
for(int j = 1 ; j < ve[i].size() ; j ++ ) {
all.push_back(all[j - 1] - (ve[i][j] - ve[i][j - 1] - 1) + 1) ;
}
int minn = 0 , minnid = ve[i][0] ;
for(int j = 0 ; j < ve[i].size() ; j ++ ) {
if(all[j] - minn >= ansmaxx ) {
ansmaxx = all[j] - minn ;
idans = i ;
l = minnid ;
r = ve[i][j];
}
if(all[j] <= minn ) {
minn = all[j] ;
minnid = ve[i][j];
}
}
}
cout<<mpid[idans]<<" " << l<<" " <<r <<"\n" ;
}
边栏推荐
- C actual combat - high configuration version of Snake game design
- C # import CSV into MySQL database
- Vulnhub's dc9 target
- 音视频开发案例99讲-目录
- 1031 Hello World for U
- C编译器 - 隐式函数声明
- 反思 - 完美主义
- ROS2中的行为树 BehaviorTree
- Protobuf binary file learning and parsing
- Viewing application and installation of Hana database license
猜你喜欢

【深度之眼吴恩达机器学习作业班第四期】Regularization正则化总结

Detailed design of PLC program control system for washing machine

手撕二叉搜索树(Binary Search Tree)

Common MySQL errors and solutions summarized painstakingly (II)

How to share the virtual environment of pycharm to jupyter Lab

AI and the meta universe sparked a spark: human beings lost only shackles and gained all-round liberation

Roblox剑九之剑二
![[Kerberos] analysis of Kerberos authentication](/img/c5/d429bcf3c26d9476531362ef286734.png)
[Kerberos] analysis of Kerberos authentication
![[repair collection function, update login interface] knowledge payment applet, blog applet, full version open source code, resource realization applet, with 299 whole station resource data](/img/77/328bd10e97d1d78708464c5d59153a.png)
[repair collection function, update login interface] knowledge payment applet, blog applet, full version open source code, resource realization applet, with 299 whole station resource data

ROS2中的行为树 BehaviorTree
随机推荐
搭建jenkins环境并自动关联打包好的工程jar进行自动发布
NOR flash application layer operation
Soft restart
Roblox sword nine sword two
【工控老马】PLC六路抢答器系统设计详解
C # import CSV into MySQL database
SAP ui5 Beginner (I) Introduction
【深度之眼吴恩达机器学习作业班第四期】Logistic Regression 逻辑回归总结
AI deep dive of Huawei cloud
Detailed explanation of route (Jiuyang Scripture)
Up and down transitions in polymorphism
手撕二叉搜索树(Binary Search Tree)
Embedded product anti-theft version
SQL injection bypass (6)
C mqtt subscription message
Reflection - project management thinking of small and medium-sized companies - make the products first and the functions first
【修复收藏功能、更新登录接口】知识付费小程序、博客小程序、完整版开源源码、资源变现小程序,带299整站资源数据
STM32基于HAL库的USART+DMA使用
征文投稿丨使用轻量应用服务器搭建博客环境
【kerberos】kerberos 认证浅析