questions that have no specific number of input tests on ACM -
questions that have no specific number of input tests on ACM -
i'm trying submission on baskets of gold coins problem on acm-icpc live archive (https://icpcarchive.ecs.baylor.edu) number of problem 3576 i've written code , gave right reply when tried submit on website online justice didn't take (time limit exceeded error) thing it's not possible programme take more 3 minuets it's simple programme question didn't how many time must input had utilize loop don't know when end code wrote
class="snippet-code-css lang-css prettyprint-override">#include <stdio.h> int n,w,d,weight; int search(); int main(){ scanf("%d %d %d %d",&n,&w,&d,&weight); while((n>1 && n<=8000) && (0<w && w<=30) && (d<w)){ printf("%d\n",search()); scanf("%d %d %d %d",&n,&w,&d,&weight); } return 0; } int search(){ int n=n-1; int sum = n*(n + 1)/2; if(weight == sum){ return n; } else{ int sum1= sum*w; return (sum1-weight)/d; } }
i tried ways like
class="snippet-code-css lang-css prettyprint-override">while(scanf("%d %d %d %d",&n,&w,&d,&weight)) while(1) while(n!=eof)
but had same response. how can end while loop online justice take code?
for problems don't have exact amount of test cases must read input until eof (end of file).
since you're using c, scanf function returns number of values read , assigned, can maintain reading blocks of 4 numbers:
while(scanf("%d %d %d %d",&n,&w,&d,&weight) == 4){ printf("%d\n",search()); }
another trick utilize while loop maintain reading first number/character of input , read rest within loop:
while(scanf("%d", &n) == 1){ scanf("%d %d %d", &w, &d, &weight); printf("%d\n",search()); }
acm
Comments
Post a Comment