Smartphones Games

QUESTION

Every one is now a days playing games on their smartphones for passing free time. Because of which there are number of game developing companies growing in the market. Not only that, each company is now flooding the market with a lot of games. With such a huge number of games in the market, for each company, with millions of users, keeping track of all the data and maintaining good user experience is now a big problem for them. \n\nOne of the very important aspect of building these games is the ability to maintain all the information about the user. This is a very important step in maintaining the user experience. No user would want to restart from the beginning of the game every time he/she restarts it. They would just then switch to a competitive game developer and that is not good for business. \n\nMost of the games now have a similar structure and some of the game companies follows the logic below in their games to handle this problem:\n\nThe game has N different parameters on which a user’s strength in the game is calculated. The game has a total of M different levels of play.\nAnd hence each parameter also gets these M levels of granularity, i.e. for each parameter itself a user can be on any one of those M levels.\nFor each parameter, the following is done:\nUser’s strength on the parameter is calculated.\nEach of the M levels have some strength value associated with them such that the strength value grows when you move from a lower level to the higher level. It may happen that any two consecutive levels have same required strength.\nIf a user’s strength is more than or equal to the strength value associated with a level, he/she is said to be fit to be on that level of the game for this parameter.\nThe level for this parameter is the maximum level for which a user satisfies the above criteria.\nThe level of the game a user is on, is decided from its level in all of the N parameters of the game as follows:\nFor each parameter, the level user is on for that parameter is computed as described above.\nThe level of game at which a user is the minimum of all the levels in each of the N parameters.\nYou are now interested in building a game for the smartphone user’s as well. But before that, you would need to solve this problem effeciently. Given the strength of user’s for each parameter, print the level they are on. \n\nInput:\nThe first line of the input contains three space separated integers, N, M and Q. (N is the number of parameters, M is the number of levels, and Q is the number of queries that you have to answer.) \nNext N line contains M space separated integers, the ith line contains the M strength values for the M levels of the ith level. \nNext Q lines, each contains N space separated integers, the strength of a user in each of the N parameters. \n\nOutput:\nPrint Q lines, one for each query. For each query, print the level on which that user is. \n.

“TESTCASE_1”: “2 3 3\n10 20 30\n7 14 100\n11 7\n35 13\n100 1002\n###—###SEPERATOR—###—\n1\n1\n3”, “TESTCASE_2”: “3 4 2\n13 21 30\n7 20 90\n5 9 12\n10 6 2\n30 11 2\n109 200 1002\n###—###SEPERATOR—###—\n0\n4”, “TESTCASE_3”: “3 4 4\n69986 692862 2819563 2819563 \n4072 4072 1502348 2190462 \n264253 264253 1911655 \n354505 4385707 7654565\n1253768 1253768 1253768 \n1521206 1521206 2306736\n###—###SEPERATOR—###—\n4\n2\n2\n2”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <stdio.h>
int a[100][5000],m;
int searchindex(int b[],int j,int low,int high)
{
	int mid;
	mid=(low+high)/2;
	//printf("%d %d %d %d %d %d\n",low,high,mid,j,a[j][mid],b[j]);
	if(b[j]>=a[j][mid] && b[j]<a[j][mid+1])
	return mid;
	else if(b[j]<a[j][mid])
	return searchindex(b,j,low,mid);
	else
	return searchindex(b,j,mid+1,high);
}
 
int main()
{
    int n,q,lev,ans,i,j;
    scanf("%d %d %d",&n,&m,&q);
    int b[n];
    for(i=0;i<n;i++)
    {
    	for(j=0;j<m;j++)
    		scanf("%d",&a[i][j]);
    }
    for(i=1;i<=q;i++)
    {
    	ans=m;
    	lev=ans;
    	for(j=0;j<n;j++)
    	{
    		scanf("%d",&b[j]);
    		if(b[j]<a[j][0])
    		ans=0;
    		else if(b[j]>=a[j][0] && b[j]<a[j][1])
    		{
    		    lev=1;
    		    if(ans>lev)
    		    ans=lev;
    		}
    		else if(b[j]>=a[j][m-1])
    		lev=m;
    		else
    		{
    			lev=searchindex(b,j,0,m-1);
    			lev++;
    			if(ans>lev)
    			ans=lev;
    		}
    	}
    	printf("%d\n",ans);
    }
    return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.