Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 – Elimination Round 2), problem: (B) Sea Battle Solution in C/C++

Hi Guys , I Just Tried to solve the Sea Battle problem , hope you might like it , please share if you’ve any better code .

#include<stdio.h>
#include<stdlib.h>
typedef unsigned u;
char S[222222];u Q[222222],Qi;
int main()
{
u n,a,b,i,j,k;
scanf(“%u%u%u%u%s”,&n,&a,&b,&k,S);
for(i=-1,j=0;++i<n;) { //printf(“!%u \’%c\’ %u\n”,i,S[i],j); if(S[i]==’1′)j=0; else if(++j==b) {Q[Qi++]=i;j=0;} //printf(“>%u \’%c\’ %u\n”,i,S[i],j);
}
printf(“%u\n”,Qi-(–a));
for(i=a-1;++i<Qi;)printf(“%u%c”,Q[i]+1,i+1!=Qi?#8217; ‘:’\n’);
return 0;
}

Hi Guys , I Just Tried to solve the Sea Battle problem , hope you might like it , please share if you’ve any better code .

#include<stdio.h>
#include<stdlib.h>
typedef unsigned u;
char S[222222];u Q[222222],Qi;
int main()
{
u n,a,b,i,j,k;
scanf(“%u%u%u%u%s”,&n,&a,&b,&k,S);
for(i=-1,j=0;++i<n;) { //printf(“!%u \’%c\’ %u\n”,i,S[i],j); if(S[i]==’1′)j=0; else if(++j==b) {Q[Qi++]=i;j=0;} //printf(“>%u \’%c\’ %u\n”,i,S[i],j);
}
printf(“%u\n”,Qi-(–a));
for(i=a-1;++i<Qi;)printf(“%u%c”,Q[i]+1,i+1!=Qi?#8217; ‘:’\n’);
return 0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

7 Reasons This Viral Kitchen Gadgets Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Hong kong banks back student housing property boom

In an evolving commercial real estate landscape, Hong Kong banks are increasingly shifting their focus toward a rapidly growing asset class: student housing. Driven...

7 Reasons This Viral Kitchen Gadgets Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.If you had told me six months ago that a single purchase would change how...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!