Общий форумDoes the statement mean that 42 people won't come out on stop number 1? What is the answer for this test: 3 3 3 1 2 -1 2 3 -1 1 3 -1 2 07:00 1 07:01 1 ? 55 55 I guess But if so, then the problem condition is incorrect because of: "Everybody who wants to get into a bus comes to a bus stop in advance, no later than at 06:59". According to this test it means that all 13 people who entered the bus with Leonid had to enter the bus, which came 1 minute earlier, because they wanted to go from station #1 to the station #2. So what should we think? Does it mean that those 13 people entered and immediately escaped from this bus, understanding this is not their bus? :) I think this test is incorrect. There can't be 42 papassengers in the bus which started its travel in 07:01. All these passengers should take previous bus. What's wrong ? #include <math.h> #include <stdio.h> #define PI 3.1415926535 int main() { double R,a,S,t; scanf("%lf%lf", &a, &R); t = sqrt(2.0)*a; if( R < (a/2.0) ) { S = PI*R*R; } if( R >= t/2.0 ) { S = a*a; } if( R < t/2.0 ) { S = PI*R*R - 4*( acos( a/(2.0*R) )*R*R - R*R*sin( 2*acos( a/(2.0*R) ) )/2.0); } printf("%.3lf\n", S); return 0; } AC. I had to "return" and "printf" in each "if"... Edited by author 27.04.2010 23:34 Edited by author 27.04.2010 23:34 Or maybe just use if ... else ... if else? #include <iostream> long int bin( long int a[], long int k, int low , int high ); long int count = 0; int main() { int n,i; std:: cin >> n; long int *A = new long int[n]; for( i=0; i<n; ++i ) std::cin >> A[i];
long int m,j,key; std::cin >> m; long int *B = new long int[m]; for ( j=0; j<m; ++j ) std::cin >> B[j];
for ( j=0; j<m; ++j ) { key = B[j]; if (bin(A, key, 0, n-1)) ++count; }
std:: cout << count; delete [] A; delete [] B; return 0; } long int bin( long int a[], long int k, int low , int high ) { int middle; while(low <= high) { middle = low + high; if (k == a[middle]) return a[middle]; else if(k < a[middle]) high = middle-1; else low = middle+1; } return 0; } Don't use cin/cout in the case of big input/output. Use scanf("%I64d",&x)/printf("%I64d",x); Edited by author 29.04.2010 17:15 I changed it...thank's. middle = (low + high)/2 there's no TLE . 0.562 Edited by author 30.04.2010 00:10 middle = low + high; ???? Edited by author 29.04.2010 23:57 Edited by author 29.04.2010 23:58 what to do when the number of '!' is larger then n? for example 3 !!!!!! Just Fuck up and write 'N' It could be 1. Which is more realistic than, say, 'N' 1) 5 !!!!!! - 5 2) 2 !!!! - 2 so...output just N 3 !!!!! here n=3 and k=5 (>3) now (3 mod 5) = 3 so answer should be n * (n-k) *(n-2k)....(n mod k) = 3 :-) I tried to solve it with a stupid exhaustive search, but for 99999999 it will be very much!!! Is there the formul with which I can solve this problem? Edited by author 01.05.2010 18:45 Машина может взять числа только из разных списков или можно взять из одного? The machine can only take the number of different lists, or you can take from one? Two numbers should be chosen from different lists. То есть с каждого списка может быть взято только одно число? Не может быть такого, чтобы взяли оба числа из одного списка? That is, with each list can be taken only one number? It can not be to have both numbers from one list? what's the problem for test 7 with 1001.pas? pls. I wrote a primitive solution for this problem (there were more efficient ones discussed here, but I tried to solve task by myself first). But that's not a point. It crashed again and again with "Stack Overflow", though I can't understand why. It is correct: I compiled it with GCC-G++, generated precalculations and get AC. But why "Stack Overflow"? [C++] #include <iostream> #include <cstring> using namespace std; int main() { int n; double f[501][501]; memset(f, 0, sizeof(f)); cin >> n; f[2][2] = 1; for (int i = 3; i <= n; i++) { f[i][i] = 1; for (int j = 1; j <= i; j++) for (int k = j + 1; k < n; k++) f[i][j] += f[i-j][k]; } double sum = 0; for (int i = 1; i < n; i++) sum += f[n][i]; cout.precision(0); cout.setf(ios_base::fixed); cout << sum << endl; return 0; } Stack size is 1MB. Size of array "b" is about 2MB. To avoid "Stack Overflow" you can: 1. declare "b" as global varialbe; 2. add directive (see also http://acm.timus.ru/help.aspx?topic=cpp) #pragma comment(linker, "/STACK:16777216") 1Mb? Strange, that only now I expirienced this. Thank you! #include<stdio.h> long mx,Matrix[1010][1010],i,j,k,y,sum,dim; int main() {
while(scanf("%ld",&dim)==1) { mx=-99999;sum=0; for(i=0;i<101;i++) for(j=0;j<101;j++) Matrix[i][j]=0; for(i=1;i<=dim;i++) for( j = 1 ; j <= dim ; j++) { scanf("%ld", &Matrix[i][j]); Matrix[i][j]+= Matrix[i][j-1] + Matrix[i-1][j] - Matrix[i-1][j-1]; if(mx < Matrix[i][j]) mx = Matrix[i][j]; } for(i = 1; i <= dim ; i++) for(j = 1; j <= dim ; j++) for( y = 1; y < i ; y++) for( k = 1 ; k < j ; k++) { sum = Matrix[i][j] - Matrix[i][k-1] - Matrix[y-1][j] + Matrix[y-1][k-1]; if(mx < sum) mx = sum; sum = 0; } printf("%ld\n",mx); } return 0; } #include<stdio.h> long mx,Matrix[1010][1010],i,j,k,y,sum,dim; int main() {
while(scanf("%ld",&dim)==1) { mx=-99999;sum=0; for(i=0;i<101;i++) for(j=0;j<101;j++) Matrix[i][j]=0; for(i=1;i<=dim;i++) for( j = 1 ; j <= dim ; j++) { scanf("%ld", &Matrix[i][j]); Matrix[i][j]+= Matrix[i][j-1] + Matrix[i-1][j] - Matrix[i-1][j-1]; if(mx < Matrix[i][j]) mx = Matrix[i][j]; } for(i = 1; i <= dim ; i++) for(j = 1; j <= dim ; j++) for( y = 1; y < i ; y++) for( k = 1 ; k < j ; k++) { sum = Matrix[i][j] - Matrix[i][k-1] - Matrix[y-1][j] + Matrix[y-1][k-1]; if(mx < sum) mx = sum; sum = 0; } printf("%ld\n",mx); } return 0; } Edited by author 28.04.2010 16:00 Edited by author 28.04.2010 16:01 Edited by author 28.04.2010 16:01 What's wrong with my program??? #include <iostream> using namespace std; pair<int,int> FindAnswer(const char *arr, const int &N, const int K); int main(void) { // Inputs data int N, K; (cin >> N >> K).get(); // Creates an extra array char *arr=new char[N]; int length=0; int pos=-1; pair<int,int> res(-1,-1); char ch[1]; while(pos!=N-1) { while(pos!=N-1 && cin.read(ch, 1) && cin) { // Reads the next character if(ch[0]=='\n') continue; ++pos; // Inserts the digit to the array if(ch[0]!='*') arr[length++]=ch[0]; // Resets the array and finds the result else { if(length>=K) { pair<int,int> tmp=FindAnswer((const char *)arr, length, K); if(tmp.first<res.first) { res.first=tmp.first; res.second=pos-length+tmp.second; } } length=0; } } } // Outputs the result if(res.second==-1) cout << 0 << endl; else cout << res.second+1 << endl; return 0; } // Function determines the result pair<int,int> FindAnswer(const char *arr, const int &N, const int K) { int best=0; int res=0; int i; for(i=0; i<K; ++i) best+=arr[i]-'0'; int prev=best; for(i; i<N; ++i) { int tmp=prev-arr[i-K]+arr[i]; if(tmp<best) { best=tmp; res=i-K+1; } prev=tmp; } return make_pair(best, res); } Edited by author 14.03.2007 16:08 If you have WA#3 try to use this simple test: 1 1 9 Right answer is "1", of course. i've got tl on tets 7 cannot you say why? i just calculate gcd of all numbers Edited by author 26.04.2010 21:02 Edited by author 26.04.2010 21:03 How is this possible? I get different results with same code and same test cases? Cheers! Help Edited by author 25.04.2010 21:50 Edited by author 25.04.2010 21:50 Of course You can't solve this in O(n). Limitations is to high. Just try to find out a O(1) solution! =) program p1028; var s,l:array[0..16000] of longint; x,y,n,tot,i:longint; procedure ins(x,left,right:longint); var mid:longint; begin mid:=(left+right) div 2; if x>mid then begin inc(tot,s[mid]); ins(x,mid+1,right); end; if x=mid then begin inc(tot,s[mid]); inc(s[mid]); end; if x<mid then begin inc(s[mid]); ins(x,left,mid-1); end; end; begin readln(n); for i:=1 to n do begin readln(x,y); tot:=0; ins(x,0,32002); inc(l[tot]); end; for i:=0 to n-1 do writeln(l[i]); end. Thx a lot!!! Edited by author 17.08.2009 09:40 i also WA#9 Orz So do I. It solves with binary tree or sqrt-decomposition. 9 9 WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW WWWWWWWWW 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 correct answer WBWWBWWBW BWWWBWWWB WWWWBWWWW WWWWBWWWW BBBBBBBBB WWWWBWWWW WWWWBWWWW BWWWBWWWB WBWWBWWBW > '[%]' like '[%]' In the template [%] presents literally just '%' as single char. String however is literally is '[%]' And those obviously are not the same ;) What right answer on sample test data? 0.007142857143 on corners, 0.011904761905 on sides and 0.019047619048 on the center 7x7 square Edited by author 24.04.2010 23:37 After wa1 many times i submit programms that should got CE (i print some strings,not numbers) but got wa1. Also i print nothing - again wa1,but not CE. It's very strange. May be checker to this problem is incorrect? |
|