AC Srinivas
BAN USERone implementation, if two loops meant two nested loops i.e O(n^2).
#include<cstdio>
#define MAX 100
int main()
{
//freopen("input.txt","r",stdin);
int n,a[MAX][MAX],i,j;
scanf("%d",&n);
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)scanf("%d",&a[i][j]);
int start_i=1,end_i=n,start_j=1,end_j=n;
for(i=start_i;i<=(n+1)/2;i++)
{
for(j=start_j;j<end_j;j++)
printf("%d ",a[i][j]);
for(;i<end_i;i++)
printf("%d ",a[i][j]);
for(;j>start_j;j--)
printf("%d ",a[i][j]);
for(;i>start_i;i--)
printf("%d ",a[i][j]);
start_i++;end_i--;start_j++;end_j--;
}
return 0;
}
sorting the list ->[0,1,2]
the first positive missing element is 3.
can be done using segment trees. See:
community.topcoder.com/tc?module=Static&d1=tutorials&d2=lowestCommonAncestor
O(preprocessing: n, query: n^1/2)
appending the string with itself(since circular) and finding substrings(from position i to i+l)
(i.e) HELLO -> HELLOHELLO
min=s; l=s.size();
s+=s;
for(i=0;i<l;i++)
{str=s.substr(i,i+l);if(str<min)min=str;}
greedy algorithm
prev_pitstop=0;
for(i=0;i<n;i++)cin>>x[i]; //coordinates of pitstops.
sort(x,x+n); // n pitstops
for(i=0;i<n;i++)
if(x[i]-prev_pitstop>50){prev_pitstop=x[i-1];cnt++;}
else if(x[i]>d)break;
cout<<cnt; //if min no. of pitstops to stop is the question.
number of positive integral solutions to the equation
X1 + X2 + X3 + ... + Xr = n (xi>=0) is (n+r-1)C (r).
in this question, no. of possibilities= no. of solutions to the equation:
X1 + X2 +... Xn + X(n+1)=x
/*X(n+1) as slack variable accounting for the >= sign*/
no of solutions = coefficient of X^x in the equation
[ (1+ X + X2 + X3 + ..... + X^m)^n ]*(1 + X + X2+......)
which should be reduced using Geometric Progression Formula.
total number of ways=m^n
Probability=no of solutions/total no. of ways.
test if prone to malicious codes like SQL injection, XSS attacks.
- AC Srinivas October 02, 2012check if there is a limit on number of invalid attempts/captchas,forgot password,etc.