Общий форумCan anybody tell me what's wrong with this? When I test the program it works fine. I end the input using ctrl-D , Is that wrong? #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> /*function to reverse a string*/ void strrev(char string[256]) { char reverse[256]; int i,j; i=strlen(string);
for (j=i-1;j>=0;j--) { reverse[i-1-j]=string[j]; } reverse[i]='\0'; strcpy(string,reverse); } int main(void) {
int k=0,i=0,j,different=0,start=0; int c; char stream[256]; char num[256]; char copy[256]; double number; while((c=getchar())!=EOF) { stream[i]=c; j=i; i++; }
for (k=j;k>=0;k--) { if(isdigit(stream[k])!=0) { if(isdigit(stream[k-1])!=0) { num[start]=stream[k]; start++; } else { num[start]=stream[k]; num[start+1]='\0'; // printf("%s\n",num); strrev(num); // printf("%s\n",num); strcpy(copy,num); number=strtod(copy,NULL); printf("%0.4f\n",sqrt(number)); start=0;
} } } return 0; } What is Fail (validator)? Checker returned this error on test 4 for my some crazy solution. Validator is fixed. You have got WA on test 4. Got real pleasure when was solving it. But why are limitations so small? The jury solution builds the correct answer for n=30 fast enough, so it is possible to solve this problem without precalc. We decided to leave it like that. ignore it..just my mistake Edited by author 22.08.2009 13:35 Is it a precision problem? who can give me some useful tests? Can you say me what answer does my program give at test #2; I know this test is 1 2 3 4 0 and at my computer i have answer 1 2 3 4 and I'm sure it's right answer; but I have WA2 at Timus, and I really don't like it. You can submit this program to see why test 2 is 1 2 3 4 0: #include <iostream> using namespace std; int main() { int a, b, c, d, e; scanf("%d",&a); if (a==3) {printf("2 2 3 4 4 5 3");return 0;} scanf("%d%d%d%d",&b,&c,&d,&e); if (a==1 && b==2 && c==3 && d==4 & e==0) while(1); } You'll get TL 2. Edited by author 21.08.2009 23:12 Never mind, I just had local bool array and didn't initialize it x_X. I'm now interested, what variables should I initalize; I usually think global arrays are filled with 0 at start of program, is it right? i decompose graph into connected components (by one dfs) after that i count diameter of each component(by one special_dfs) and refresh global_variable if need. my programm works at all my tests and sample test too. I dont understand the problem itselk. what does K stands for? Hi, for the "F" parameter, I can see that it is the hight of the binary tree. But in my AC program, I didn't even use it. below is my program, anything I've missed? ====================== code deleted ============================== Edited by moderator 01.10.2022 12:26 I added some new tests. Look, your code has got WA. :) Edited by author 29.06.2008 12:03 Thank you. Now, I feel more realistic, but have to start researching again:) Oops, I modified my program, I missed some cases in the original one. But still got AC without using F... My AC program don't use F too. In autor's solution uses F or not??? Я раз 10 прочитал задачу, и до сих пор не понял, что от меня требуется((((( Автору зачОт)))) +1 :))) Very bad statements and hard to understand :((( 2admin : Author's solution used all numbers or not? You are to find distance between two nodes in tree. D and E - heights of these nodes; Ep and Dp - numbers of leaves which are nearest to these nodes (in this tree only leaves are numbered); F - height of the tree. Thanks I got AC, but statements is hard to understand :( What is the trick??? If there are several rules that can be used the the word is to be carried to the next line according to the rule that provides the minimal length of the carried part of the word. I have WA3. May be I don't understand this problem. #include <stdio.h> int main() { int n,a[20],i,s=0,rez=0; scanf("%i",&n); for (i=0; i<n; i++) { scanf("%i",&a[i]); s=s+a[i]; } /*for (i=0; i<n; i++) printf("%i",a[i]);*/ int maxs,maxi,j,sdop,k; bool ok=true; while (ok) { maxs=0; for (i=0; i<n; i++) { sdop=0; for (j=i; j<=i+2; j++) { if (j>n-1) sdop=sdop+a[j%n]; else sdop=sdop+a[j]; } if (sdop>maxs) { maxs=sdop; maxi=i; } }
s=s-maxs; rez=rez+s;
int d1,d2,d3; d1=maxi; if (maxi+1>n-1) d2=(maxi+1)%n; else d2=maxi+1; if (maxi+2>n-1) d3=(maxi+2)%n; else d3=maxi+2; a[d1]=0; a[d2]=0; a[d3]=0;
ok=false; k=0; while (!ok && k<n) { if (a[k]!=0) ok=true; else k++; } } printf("%i",rez); return 0; } Check please test 33. It's very strange that dp ( subset with given sum ) don't work. Maybe there is a bad checker. Both test 33 and checker are correct. Look for a bug in your solution. Good luck! Thank's. Stupid error in my algo. Can anybody explain me, where am I wrong? Definitions: ac, ab, bc - corresponding lengths acb - angle between (ca) and (cb) Such code: ... acb = acos((ac*ac + bc*bc - ab*ab) / 2.0 / ac / bc); .. gets AC. Such code: ... double spv(point x1, point x2, point y1, point y2){ int i; double res = 0; for (i=1; i<=n; i++){ res += (x2.coord[i] - x1.coord[i]) * (y2.coord[i] - y1.coord[i]); } return res; } ... acb = acos(spv(c,a,c,b)/ac/bc);... ... gets WA25. I had always thought that these two fragments must yield the same result. Why don't they? me too. If you get WA27, use type double I use n^4 algorythm and works for 0.015 secs. :P please, any hint Help Me Please. WA#2 what is test 2. My Code: import java.util.Scanner; public class Rubbits { public static void main(String[] args) { Scanner rb = new Scanner(System.in); int n = rb.nextInt(); long [] a = new long [n]; int i,j,k,m; for ( i = 0; i < n; i++) { a[i] = rb.nextInt(); } for ( i = 0; i <n; i++) { if (a[i]==1){ System.out.println("0");
} else if(a[i]==2) System.out.println("1"); else{ for ( j =2; j < a[i]; j++) { k =(int)a[i]/j; m = k*j; if (a[i]-m>=k) { System.out.println(j); break; } }
} } } } test #2 n=1 output 2 n=2 output 3 n=3 output 2 |
|