Vous êtes sur la page 1sur 5

========================================================= TEAM STATS ON PROBLEMS: JAILOR : 7/37 MERGE : 4/8 PROXY : 1/11 SMALL : 8/40 TYRES : 0/12 =========================================================

Problem: JAILOR: This problem is well known as Josephus Problem. The problem was relatively easier to solve as you might have already come across this problem or otherwise the formula is easily available. Out of 37 contestants who submitted for this problem, only 7 were able to get this problem accepted. Team:qwerty was the first to submit it successfully. -----------------------------------------------// qwerty's code: int N, B , C, M; int formula (int n, int k) { if (n == 1) return 0; int kiplus1 = 1 + (k * B + C) % M; return (formula (n-1,kiplus1) + k) % n; } int main(){ int test,K; cin>>test; while(test--){ cin>>N>>K>>B>>C>>M; cout<<formula(N,K)+1<<"\n"; } } ------------------------------------------------

==================================================================== Problem: MERGE In this problem, the worst case or the maximum scoring permutation is the case where maximum no of comparison are done in the merge procedure. The merge procedure compares the elements in each array and then removes the minimum. So the worst case in comparison of two arrays of size M and N would have a total of M+N-1 comparisons. e.g. merging of {1,3,7} and {4,6,9} has total 5 comparisons; Here, notice that elements 7 and 9 are the two largest numbers in the combined array and they are in different arrays => this made the case worst. So, after the division in the array has taken place, all the mergings should have the maximum no of comparisons. Arranging the numbers this way, we find the required permutation. Once the pattern is clear, you can directly fill the numbers like this: -----------------------------------------------// my code: int seq[MAX+1]; int comp[MAX+1]; int val; void doit(int a,int b){ if(a>b) return; int m=(a+b)/2; seq[m]=val--; doit(m+1,b); doit(a,m-1); } int main(){ // comp[i] contains the maximum no of comparisons for // an array of size i which actually forms a sequence. comp[1]=0; for(int i=2;i<=MAX_LIMIT;i++) comp[i]= (i-1)+comp[i/2]+comp[i-i/2]; int tc; scanf("%d",&tc); while(tc--){ int N; scanf("%d",&N); seq[N-1]=N; val=N-1; doit(0,N-2); printf("%d\n",comp[N]); for(int i=0;i<N;i++) printf("%d%c",seq[i],(i==N-1)?'\n':' '); } } ------------------------------------------------

Problem: PROXY Some contestants who tried for this problem misunderstood it. The problem was simple. It demanded the maximum no of calls Roll#1 can attend. Note: to attend anyone's call, Roll#1 has to be at his place. Let res[i] be the maximum no of calls that can be attended by Roll#1 after he reaches the place of i'th person in the class. Suppose class is MxN and res[i] is under consideration then, res[i] is 1 plus the maximum value amongst all res[i+j] (where i+j<=M*N), which are at distance less than or equal to j from him i.e. they are reachable. This is an O(n^2) solution. I believe an efficient solution does exist. -----------------------------------------------// my code: int studi[MAX]; int studj[MAX]; int dist(int a,int b){ return abs(studi[a]-studi[b])+abs(studj[a]-studj[b]); } int main(){ int tc; scanf("%d",&tc); int res[MAX]; while(tc--){ int M,N,t; scanf("%d%d",&M,&N); for(int i=0;i<M;i++) for(int j=0;j<N;j++){ scanf("%d",&t); studi[t]=i; studj[t]=j; } int next[MAX]={0}; for(int i=M*N;i>=1;i--){ res[i]=1; for(int j=i+1;j<=M*N;j++) if(dist(i,j)<=(j-i) && res[i]<res[j]+1){ res[i]=res[j]+1; next[i]=j; } } printf("%d\n",res[1]); int i=1; printf("1"); while(next[i]){ printf(" %d",next[i]); i=next[i]; } printf("\n"); } } -----------------------------------------------====================================================================

Problem: SMALL Every timed-out solution submitted to this problem was generating all possible sums by a native 2^N approach, which can also be done by dividing the numbers into two sets and then generating all possible sums for each set separately. Then a check could be performed on all generated sums to find the presence of the required sum. -----------------------------------------------// Team:concept's code: long long nums[34]; long long L[100000],R[100000]; int main(){ int T; scanf("%d",&T); while(T --){ long long A; int i,j,N; cin >> N >> A; memset(L,0LL,sizeof L); memset(R,0LL,sizeof R); for(i =0; i < N; ++i) scanf("%lld",nums + i); int mid = (N + 1)/2; int Lmax = (1 << mid),Rmax = (1 << (N - mid)); for(i =0; i < Lmax; ++i){ for(j = 0; j < 15; ++j){ if(i & (1<< j))L[i] += nums[j]; } } for(i =0; i < Rmax; ++i){ for(j = 0; j < 15; ++j){ if(i & (1<< j))R[i] += nums[j+mid]; } } sort(L, L + Lmax); sort(R, R + Rmax); bool b = 0; for(i = 0; i < Lmax; ++i){ b = b || binary_search(R,R + Rmax,A L[i]); } if(b) cout << "YES" << endl; else cout << "NO" << endl; } return 0; } -----------------------------------------------====================================================================

Problem: TYRES The solution required a good insight of the problem. Given T tyres, each with some strength, N of which can be used at a time and the maximum distance travelled is to found out. Note that the maximum distance that is possible is (total strength of all the tyres)/N = S/N. Sort the strengths of the tyres and then find the tyre with the biggest strength. If the biggest strength is greater than or equal to S/N then this tyre will be used in all S/N unit distances. Now the maximum distance that can be travelled is determined by N-1 tyres and similar procedure is applied recursively. -----------------------------------------------// my code: int b[MAXT+1]; int main(){ int tc; scanf("%d",&tc); while(tc--){ int N,T; scanf("%d%d",&N,&T); for(int i=0;i<T;i++) scanf("%d",&b[i]); sort(b,b+T); long long res=(long long)1e12; long long sum=0; for(int i=0;i<T-N;i++) sum+=b[i]; for(int i=T-N;i<T;i++){ sum+=b[i]; long long t=(i+1)-(T-N); res=min(res,sum/t); } printf("%lld\n",res); } } -----------------------------------------------====================================================================

We hope you enjoyed the contest and the problem set. We would like to thank all the participants for participating in the contest, inspite of the sluggish response of our site. We once again apologize for the delays and other issues with the contest. THANK YOU once again. HOPEFULLY NEXT YEAR WE WILL HAVE A BETTER BACK UP SYSTEM!.

PROBLEM SETTER: JUDGE :

deepak pandey. neerav kumar & ashish Agarwal.

Vous aimerez peut-être aussi