Общий форумI've changed input reading method from "read line by line" to "read word by word", and got AC because of it. Which seems strange. Probably, test 9 is incorrect. I suppose my error is either in the procedure of scanning/printing. My program receives input and prints output using file pointers. FILE *fi,*fo; fi = stdin; fo = stdout; And the program reads/writes by fscanf/fprintf. If you have any knowledge concerning the input/output for this problem, please comment. #include <iostream> using namespace std; int main() { int a,b,i=0,x=0,y=0; cin>>a>>b;
while(x+b<=a) { x=x+b; i++; } y=a-x; if(y>0) { i++; } while((y+b)<a) { y=y+b; i++; } i++;
cout<<i;
return 0; } Solved numerically, but with complete botva. Is there some beautiful geometric solution? If yes - any clues how to do it? Thanks. There is really beautiful geometric solution. Try to think about rotation. My solution is geometric with little cheat (3 cases, 2 solves geometrically, in third (3 lines have one point of intersection) - answer is any triandle with length of edge 1.1*1e-6 and center in the point of intersection), but WA21 :( Edited by author 05.05.2013 02:07 Edited by author 05.05.2013 02:07 Edited by author 05.05.2013 02:07 #include<stdio.h> int main(){ int m,n; while(scanf("%d %d",&m,&n) == 2){ if(m == 0 || n == 1){ printf("yes\n"); }else{ printf("no\n"); } } return 0; } Why do you use "while" for reading? Time Limit Exceeded Test#12 what do? I think we only remember 1 to 2^i this mean G(1,i) then F(1,N]=F(1,2^i)+i-1+F(2^i+1,N) ==> F(1,N)=G(1,i)+i-1+F(2^i+1,N) while the last F(2^i+1,N)=F(1,N-2^i-1) and so on certainly f(1,1)=0; Edited by author 04.05.2013 19:28 I just use something like low_bit and calc the answer easily in logN time. You may use Abs(Dis(1,A) - Dis(1,B)) it is a good way to solve this problem. Sorry for my poor English. Edited by author 14.11.2005 21:19 15 strings - And AC - Cool!!! - time 0.015 почему возникает такая проблема? код вроде соответствует примеру, приведенному в руководстве. В Visual Studio 2010 все работает. что делать? почему возникает такая проблема? код вроде соответствует примеру, приведенному в руководстве. В Visual Studio 2010 все работает. что делать? Unable to clear test3. please help #include<stdio.h> #include<math.h> int main() { float r; float sum=0.0; int i,n,nxt=0; scanf("%d %f",&n,&r);
float dim[n][2]; for(i=0; i<n;i++) { scanf("%f%f",&dim[i][0],&dim[i][1]); }
for(i=0;i<n;i++) { if(i+1==n) nxt=n; else nxt=i+1; float y=pow((dim[i][0]-dim[nxt][0]),2); float z=pow((dim[i][1]-dim[nxt][1]),2); y=y+z; sum+=sqrt(y);
} sum+=2*3.14159*r;
printf("%.02f\n",sum); return 0; } First of all I suppose the graph is a tree (M=N-1 and all vertices are connected, see the text). Is it a tree? I choose one vertex (let it be 1) and consider it as root. I perform breadth first algorithm starting from the root and obtain vertices in increasing order of distances (in the same time I obtain the parent for each vertex). The result is the array C[1..N]. From N downto 1 I search for available C[i] and P[C[i]] (P[C[i]] is the parent for C[i]). I mark C[i] and P[C[i]] not to be used furthermore (unavailable). The edge [C[i],P[C[i]] is part of solution and the final result is WA on test 7... what's wrong ? Edited by author 15.11.2005 20:32 The algorithm was correct but I ignored the output format ... AC now Hi, I have the same problem with WA #7, in what way was the output format wrong? I don't know why Please help if you can #include <stdio.h> #include <stdlib.h> #include <math.h> #include <malloc.h> int main() { char* Buffer =(char*) calloc(1, sizeof(*Buffer)); int i=0,j, ch,k; double value =0.0f; int wasValueReadingStarted=0, NeedToBePrinted=1; ch = getchar(); while (ch != EOF) { if(i) { Buffer = (char*)realloc(Buffer, (i+1)*sizeof(*Buffer)); } Buffer[i]=ch; ch = getchar(); i++; }
j = i-1;
while (j>=0) { ch = Buffer[j]; if (ch ==' ' || ch == '\t' || ch == '\n') { k=0; if (wasValueReadingStarted && NeedToBePrinted) { printf("%.4f\n", sqrt(value)); NeedToBePrinted=0; value = 0.0f; } } else { value += (ch-'0')*pow(10,k); wasValueReadingStarted = 1; NeedToBePrinted=1; k++; } j--; } if (wasValueReadingStarted && NeedToBePrinted) printf("%.4f\n", sqrt(value)); return 0; } Edited by author 03.05.2013 17:36 main() { long n,sumperv=0,sumposled=0,perv,posled; int flag=0; scanf ("%ld",&n); perv=(n+1)/1000; posled=(n+1)%1000; while (perv) { sumperv+=perv%10; perv/=10; } while (posled) { sumposled+=posled%10; posled/=10; } if (sumperv==sumposled) flag=1; perv=(n-1)/1000; posled=(n-1)%1000; sumperv=0; sumposled=0; while (perv) { sumperv+=perv%10; perv/=10; } while (posled) { sumposled+=posled%10; posled/=10; } if (sumperv==sumposled) flag=1;
if (flag==1) printf ("yes"); else printf ("no");
} [code delete] Edited by author 09.05.2013 15:31 Hi, Does anyone have test 12 and it's output so that I can debug my program? Edited by author 03.05.2013 12:20 Why TLE on 1 test? It takes no time on example. Any piece of advice? #include <cstdio> #include <vector> #include <cmath> using namespace std; int main() { vector<long long> n; long long a = 0; while( a != EOF) { scanf("%llu", &a); n.push_back(a); } for (int i = n.size() - 2; i >= 0; i--) { printf("%.4f\n", sqrt(long double(n.at(i)))); } return 0; } Looks like I've caught it. It freezes if ctrl+d used for EOF and it's do not response if ctrl+z used, when -1 used everything is OK. Edited by author 01.05.2013 20:12 Edited by author 01.05.2013 20:12 I think both answer would do 1. Use __int64 2. Here is some fragment of my code(and the most significant): for(x=0;x<r;x++) k+=ceil(sqrt((double)(r-x)*(r+x))); <----- be careful!! use binary search and the following relation: x^2+y^2=R^2 this staff is nice. that let me deal problem. looks like sqrt can't handle 100000*100000 also (r-x)(r+x) == r*r - x*x, but first can be handled with sqrt but second not finally, thanks at all sorry for bad english |
|