Common Board What output? 150 4 50 50 50 50 and this 200 4 50 50 50 50 My AC program outputs -1 in both cases Why output -1 for the second test??? My output for the first one is -1 and for the second one is an empty line. second test is not valid. it's given that some cards are missing... which means there is atleast one card missing Please, explain, why a man with smallest precision must not shoot before killing one of others, and give me some examples for testing my program There are trailing spaces in some lines of input in test 11. Please, check this. Edited by author 25.12.2007 02:47 Please, give me answer, don't ignore my request...(( Now N <= 100000, Time Limit is 1 sec. All tests with trailing spaces are fixed. this is my code: #include<stdio.h> #include<stdlib.h> #include<math.h> int main() { long K[5000005],N,i,j,t,value,k,count,a,flag; scanf ("%ld",&N); if (N%2==0) k=N/2; else k=N/2+1; for (i=0;i<N;i++) scanf("%ld",&K[i]); for(i=0;i<N;i++){ j=rand()%N; for(flag=0,count=1,t=0;t<N;t++){ if (K[t]==K[j]) count++; if (count>=k){ value=K[j]; flag=1; break; } } if (flag=1) break; } printf("%ld\n",value); return 0; } why Crash (stack overflow)? please help me ? define big arrays outside procedures long K[5000005] I modify small than long K[5000005] to k[500005],but it Crash (stack overflow)? change you prog to -------------- long K[5000005] int main() { long N,i,j,t,value,k,count,a,flag; scanf ("%ld",&N); ------------ or use #pragma comment(linker, "/STACK:16777216") defaut stack size ~1mb Edited by author 29.12.2007 01:18 Thanks ( KIRILL(ArcSTUpid coder:) )to solve problem of memory for me,but now answer is wrong; could you mail to me for 1510?
email: k13795263@126.com thanks; The problem in rand(); See documentation for return value. It's too small. You need something like this: t = (rand()*rand())%N; Excellent problem. Very realistic and DP works. Small advice: We should consider moments after stationary condition established: first trains went to last stations. Without this we must include 10^5 moments in Dp and will be MLE and TLE. Edited by author 30.12.2007 10:32 I think that correct answer for n=2 is 1, because if one of eagles has 2 heads and another 0 heads then IQ will be 2*0=0, isn't it? But my program had WA3 in that case. When I wrote 2 in output for n=2, I got accepted. Why? because you can have only ONE eagle with 2 heads in group, so IQ = 2. There was no obligations that group should consist of >=2 eagles... Edited by author 28.12.2007 21:55 Edited by author 28.12.2007 21:55 270 5 50 50 100 110 170 and the answer is -1 because... even the data type "long long" works only for numbers till 490 ... from 491 to 500... it gives wrong answer can any1 help please??
your solution is wrong besause answer always is less than 10^18 thanx a lot... i got my mistake #include<stdio.h> long n,a,k; void work () { long i,na,x; if (n<316227) x=2*n; else x=316227; for (i=x;i>=1;i--) { na=2*n+i-i*i; if (((na%(2*i))==0)&&(na>0)) { na=na/(2*i); a=na; k=i; break; } } } int main () { scanf ("%ld",&n); work (); printf ("%ld %ld",a,k); return 0; } Test: 10^9 Your program result: 4811 148480 My AC program result: 26263 25600 My program result: 1243 640 for n= 10^6 Edited by author 27.12.2007 22:11 #include<iostream> #include<stdio.h> using namespace std; __int64 n,a,k; void work () { __int64 i,na,x; if (n<316227) x=2*n; else x=316227; for (i=x;i>=1;i--) { na=2*n+i-i*i; if (((na%(2*i))==0)&&(na>0)) { na=na/(2*i); a=na; k=i; break; } } } int main () { cin>>n; work (); cout<<a<<" "<<k; return 0; } #include<stdio.h> long n,a,k; void work () { long i,na,x; if (n<316227) x=2*n; else x=316227; for (i=x;i>=1;i--) { na=2*n+i-i*i; if (((na%(2*i))==0)&&(na>0)) { na=na/(2*i); a=na; k=i; break; } } } int main () { scanf ("%ld",&n); work (); printf ("%ld %ld",a,k); return 0; } i've been making it for nearly a week and i still get WA on #14.who can tell me why,or give me the data? #include<iostream> #include<math.h> #define MAX 200000 #define N 350 using namespace std; int n; double map1[N][N]; struct node { int x,y; }point[N]; double dist(node a,node b) { return sqrt((double)((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y))); } void init() { cin>>n; int i,j; for(i=1;i<=n;i++) cin>>point[i].x>>point[i].y; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { map1[i][j]=dist(point[i],point[j]); //cout<<map1[i][j]<<" "; } //cout<<endl; } } double calck(node a,node b) { if(a.x-b.x!=0) return (a.y-b.y)/(a.x-b.x);else return -MAX; } int mid(node c,node a,node b) { if(a.x!=b.x) { if(abs(a.x-b.x)>abs(a.x-c.x)) return 1; }else if(abs(a.y-b.y)>abs(a.y-c.y)) return 1; return 0; } void solve() { int i,j,k,used[N][N]; double ans=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++) { ans+=map1[i][j]; used[i][j]=0; } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { for(k=1;k<=n;k++) { if(i==j || j==k || i==k) continue; if(calck(point[i],point[j])==calck(point[i],point[k]) && mid(point[k],point[i],point[j]) && used[i][k]==0 && used[k][i]==0) {ans-=map1[i][k]*2;used[i][k]=1;} } } } ans/=2; cout<<(int)(ans)<<endl; } int main() { init(); solve(); return 0; } Edited by author 12.01.2008 04:09 Edited by author 12.01.2008 04:10 Edited by author 12.01.2008 04:10 please give me some right tests... thanks... Could anybody tell me how should I read the input in "c"? use unsigned long or qword to get ac pls someone help me... i'm getting WA1 my brute force program... works for all cases ... still getting WA 1.. #include<stdio.h> long min = 1000000000; void recur(int arr[] , int n , int finished[] , int finishedCount , int total , long damage) { int i , k , l , sum , tempfinishedCount , flag , a, b , c; if( finishedCount == n ) { if( damage < min ) min = damage; return ; } if( damage > min ) return ; for( i = 0 ; i < n ; i++ ) { k=(i+1)%n; l=(k+1)%n; sum=0; tempfinishedCount=finishedCount; flag = 0; if( !(a=finished[i]) ){ finished[i] = 1; finishedCount++; sum+=arr[i]; flag=1; } if( !(b=finished[k]) ){ finished[k] = 1; finishedCount++; sum+=arr[k]; flag=1; } if( !(c=finished[l]) ){ finished[l] = 1; finishedCount++; sum+=arr[l]; flag=1; } if(!flag) continue; total -= sum; damage+= total; recur( arr , n , finished , finishedCount ,total , damage ); damage-=total; total += sum; finished[i]=a; finished[k]=b; finished[l]=c; finishedCount=tempfinishedCount; } } int main() { int n , i ,arr[21] , finished[21]={0} , finishedCount = 0 , total; scanf("%d",&n); for( i = 0 ; i < n ; i++ ) { scanf("%d",&arr[i]); total+=arr[i]; } if( n <=3 ) printf("0\n"); else { recur( arr , n , finished , finishedCount , total , 0 ); printf("%ld\n",min); }
return 0; } |
|