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?’ ‘:’\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?’ ‘:’\n’);
return 0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

How Under Desk Storage Is Quietly Changing the Game

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

Has a woman ever mated with an ape?

Throughout history, urban legends, mythology, and speculative fiction have frequently explored the boundaries between humans and animals. One of the most persistent and sensationalized...

Why Home Office Lighting Is Currently Breaking the Internet

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

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!