My MS internship 2 - The interview  

Posted by Unknown in

It was all like a joke or a dream but the company invited us for an interview. We got a mail on 1st April about it. what a day to be serious. But then w had had a talk earlier and then had an interview on 5th. It was a tough long day as the second time in two years i was out of station, the Sunday before my second mid sems in the month of April. Last time had been a successful IIT paper and this time it was an interview. I'll be really looking for something the next time around as well. Mayank and Abhishek had done some preparation and it was really up for the time to tell whether hat would fruit. We were there on time. The college had been helpful.

But it seemed that we were pulled as a part of the regular interviews. And indeed we were. Truly, now it was tough. There were seniors I don't care but they had prepared for it and were ta say formally dressed, prepared and all. And we were simple. The day had long waits as we were called. We were given two questions to do which I came here and came to know that were among the standard questions. I don't even remember as well what the questions were but we were to interact with the examiner to get in and that I should say was the main point. People from all the places were there, but indeed I felt that good. The question was basic and I gave two possible solutions to the examiner. Maybe that was watch they were judging, the number of parallel solutions that we could find out.

So in the end of it i qualified to the second round while both of them were out. They went leaving me alone. This was I think the real test- to pass out 6-8 hours a that silly place with nothing to do alone. People had friends to talk to and I was a junior to them. More so they were strange and too formal to talk to. Finally I got a chance to get the interview. This was the best part of the set. I had long one but indeed it was good, after a little struggle, I figured out almost everything. The questions for me were new but people say they were standard. One was to check out rows and column that had a zero in a binary matrix. One was a discussion of my previous problem (the written round). One was a logical one where the word phrasing was the key. There were numbered doors and serially they were toggled as the tables of one, two, three till hundred were read. Basically initially all were open. Then all multiples of 1 were toggled. Then 2 and so on. There were 100 doors and I had to figure out how many will be open. I figured that out and after that started to feel i was through this round. The answer was simple. for say 16, 8x2 and 2x8 so the toggling cancelled. But 4x4 it doesn't the perfect squares don't toggle twice to cancel.

I had a paper and so was allowed to after that and my third round was left for that time. I did not whether that was to take place. I went through the midsems, the news as started to spread. The third round then came. A sudden telephonic round.

It was a Saturday and luckily I was in my room, alone with no classes. i knew there was an interview to come but did not know when. But got that good enough. The people did consider the second year and asked me only data-structures and OS. A few logical questions and then a test whether I knew OOPs was enough and he hung up. Of the non bookish questions, one was to design an algo for the lift system, maybe because when i came here, I saw that this was the one they wanted to changed all the time.

All right this was in short how I was through. Details summary personally hi milegi, some day if I feel like to.

My MS internship - the background  

Posted by Unknown in

Okay so I am writing all the details in advance. I know I would be discussing a lot about the environment and culture once I return but I don't want my blog to miss it- so that I can redirect people when I am not willing to speak(Got it that's why I gave you the link - Also to popularize the blog) Any way here I start - I had been good at programming right from the start(even though I left computers for biology in class XI and XII). I had a safe lead in VIII & IX of over 10 marks when the subject was introduced. But I had a shock at the boards where I managed 88, while was expecting 98. I tried my best but my school was interested in only toppers - I was not. More so,you rarely get your marks corrected at ICSE, the teachers are careless at those issues. Many said it was not an error at my side but my programs had always been on the non-traditional side, those which are less understood by the people that are used to mugging up the book. All right time had passed and I had landed into Thapar.
I had computers in my first semester and I think it was there that I realized that what I considered as nothing actually was a lot and the basic programming that I used to love was indeed the problem of many. I then had to get my branch changed. I did not take that as seriously towards the going semester but took a week off before AIEEE( strange rule - you need a rank to get your branch changed and hat too better than the closing of the branch this year). I had missed CS by just one seat and this time this was not going to be repeated. Despite a marriage before that which I attended and partying it all over the week, I managed to gt my formulae revised and everyone knows that they ask nothing else at AIEEE. I got my branch changed to computers. i had meanwhile in my first year won quite a few contests and was starting to feel the contest level of the college too low. Sourabh, with an intention to do robotics invited me to join his team for IITKGP fest Kshitij. You know how I am. I don't deny till of course I know I won't do it in all cases.
We somehow go a working model made and decided to go to KGP. But I had always taken overnight there seriously and he had also seen that. Meanwhile I had a serious fever before the fest and couldn't come up in the train. But maybe luck wanted me to go and I was thee the next day, morning flight.
Robotics came out too tough. But then that opened gates for programming. I had a good four hour sleep before the contest and started there afresh. I will talk in details about the IITKGP overnight some other day. Right now what I can say is that, out of sheer luck and co-incidence we ended up sixth and in the consolation list. I had no experience to professional contest programming. Neither were we a match to the fourth year guys. And we had managed only one correct question in seven hours of the eight in the contest. but the last hour had been fruitful as i had found bugs in one of my code - a missing test case and also sourabh had come up with brute force ideas that were looking cheap but came up good.
That was my introduction to contest programming. We finalized IIT Roorkee fest for another try at robotics and more importantly one more standard contest. I meanwhile learned about the ICPC and what it takes to program there. I started a few basic learning - plan do some intermediate to advance now.
We reached IITR and as usual our robot crashed in the trial run to a state that we could not even plan to give it a proper demo on the actual course. Meanwhile IDC was one of the associate sponsors and over half the CS contests were being organized by it. We were spending time there. Mayank and all had also come for gaming and more so time pass. I had been to one more final before this where I had crashed out. But indeed all seemed preparation for this. I was sitting with Mayank and Abhishek here anybody. But this time the brain was working. We were fast and good. In the lead right from the start. Happens someday when everthing falls to place. I was guessing the algos and solving them. Mayank was coming out with strange un-makable algos while sourabh - his team did not have a single person worth while to code. In the end we finished second, after somewhat struggles as the teams suddenly came out with submissions. We were first 10 minutes before the closure. Ok this much short intro must be enough. Lets go to the interview and the trip.... Next posts plz....

Animator vs Animation  

Posted by Unknown






Any idea how you can get this made???

Wikipaedia - What's that maintains it?  

Posted by Unknown in

I am not really a critic, but then if I criticized the world's biggest encyclopaedia for its shortcommings, I should also mention some of its features that has made it to stand the test of time and opposition from teachers who considered this unauthentic.
By the way wiki is still not considered an authentic source to quote out and due its nature it'll never be but then still it provies you accurate and precise information most of the time and that I should say is its success. it has been able to successfully manage the inflowing content marking out that which is old and that which may not be accurate. At so many places you would have seen tags like citation needed, old, needs updation, etc. There is a proper team of people who at their free times go to wikipaedia to read and edit and help maintain this enormous project. And the greatest part is that its successful.
Reasons for the maintainance of wiki or some tricks that worked have been discussed a lot but I write out the tricks that made it pass the test of time.
Internationalization: An article written by say in India is viewed and analysed by a person far off say somewhere in Africa. So he is neither familiar of the concept and in many cases might not have even heard of it. With such kind of people viewing who have no sort of attachment with the subject whatsoever, no connection most probably, you can expect proper judgement.Atleast the grammar, the feel of the issue and the emotions of the author can easily be understood by the third person who can then make sure it is successful.
No Registration: Registration is not compulsory for little editting. What that makes sure is that it hardly takes time for the people to modify it. Of course, the modification is monitored.
User Page: Never thought of it when i did not have an account, but I see it now, user page is an aspect of wikipaedia that has affected it the most. Everyone want's to tell the world what he has done. So if you have a user page as a wiki user, you will atleast know that your contributions are counted and there is a place where people can come to you. Its better than sending emails and keeping problems private. There is supposed to be all open matter on wiki and so is the user page.
Openness of templates: The templates of wiki are all open and the source code free enough to be modified. So the users can come up with new ideas to decorate it.
Support for Review: The most important aspect of maintainace is to check whether false facts do not come up. And that has been maintained by the neormous support for the reviewers or those people who take responsibility to help and maintain. They will normally ahve the WIkiEd installed so no issue of editor for them. Then the task is made simple - every fact requires a direct citation, not present mark it. Marking is just two letters or three letters of typing, not at all time confusing. the links are understandable and so you don't have to explain in detail what you have marked. Plus we can discuss each topic. This means there is a proper page for topic reviews and comments to the original author to use. The editting history is saved and can always be rolled back to. There are options of locking your articles from free editors to rgistered ones so that you atleast have their track.
Unity of theme: one good thing that has come up with the bad editor is the maintainance of the look and the theme. Every page on wikipedia is similar in font, font size, heading style. this makes it look formal and presentable. It looks like a set rather than just a collection.
Culture: wikipaedia has maintained its own culture of openess and helfulness. All code is available. Peopel are ready to show how to work, and maintain the read posts for help recent. The postings form a proper forum where there is everthing a person want ( maybe not proper topics).
I accept that some of the things are really great. Cheers to them!!!

Google Code Jam Answer 3  

Posted by Unknown in ,

This one was too good a question for me. i did something couldn't pass out. I have joined topcoder for practice - all people out there help me improve.....
Fly Swatter
Problem

What are your chances of hitting a fly with a tennis racquet?

To start with, ignore the racquet's handle. Assume the racquet is a perfect ring, of outer radius R and thickness t (so the inner radius of the ring is R−t).

The ring is covered with horizontal and vertical strings. Each string is a cylinder of radius r. Each string is a chord of the ring (a straight line connecting two points of the circle). There is a gap of length g between neighbouring strings. The strings are symmetric with respect to the center of the racquet i.e. there is a pair of strings whose centers meet at the center of the ring.

The fly is a sphere of radius f. Assume that the racquet is moving in a straight line perpendicular to the plane of the ring. Assume also that the fly's center is inside the outer radius of the racquet and is equally likely to be anywhere within that radius. Any overlap between the fly and the racquet (the ring or a string) counts as a hit.

Input

One line containing an integer N, the number of test cases in the input file.

The next N lines will each contain the numbers f, R, t, r and g separated by exactly one space. Also the numbers will have at most 6 digits after the decimal point.

Output

N lines, each of the form "Case #k: P", where k is the number of the test case and P is the probability of hitting the fly with a piece of the racquet.

Answers with a relative or absolute error of at most 10-6 will be considered correct.

Limits

f, R, t, r and g will be positive and smaller or equal to 10000.

t < style="font-weight:bold;">Nothing to speak man here is what rem wrote:

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <ctime>
using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;

#define _CRT_SECURE_NO_WARNINGS
#define For(i,a,b) for (int i(a),_b(b); i <= _b; ++i)
#define Ford(i,a,b) for (int i(a),_b(b); i >= _b; --i)
#define Rep(i,n) for (int i(0),_n(n); i < _n; ++i)
#define Repd(i,n) for (int i((n)-1); i >= 0; --i)
#define Fill(a,c) memset(&a, c, sizeof(a))
#define MP(x, y) make_pair((x), (y))
#define All(v) (v).begin(), (v).end()

template<typename T, typename S> T cast(S s) {
stringstream ss;
ss << s;
T res;
ss >> res;
return res;
}

template<typename T> inline T sqr(T a) { return a*a; }
template<typename T> inline int Size(const T& c) { return (int)c.size(); }
template<typename T> inline void checkMin(T& a, T b) { if (b < a) a = b; }
template<typename T> inline void checkMax(T& a, T b) { if (b > a) a = b; }

const double pi = 2*acos(0.0);
const double eps = 1e-9;

double asin2(double x) {
double res = asin(max(-1.0, min(1.0, x)));
assert(-pi/2 <= res && res <= pi/2);
return res;
}

double inters(double x1, double y1, double x2, double y2, double r) {
assert(x1 <= x2 && y1 <= y2);
assert(sqrt(sqr(x1)+sqr(y1)) <= r);
if (sqrt(sqr(x2)+sqr(y2)) <= r)
return (x2-x1)*(y2-y1);
vector<double> xs;
xs.push_back(x1);
xs.push_back(x2);
double x = sqrt(sqr(r)-sqr(y1));
if (y1 < r && x1 < x && x < x2)
xs.push_back(x);
x = sqrt(sqr(r)-sqr(y2));
if (y2 < r && x1 < x && x < x2)
xs.push_back(x);
if (x1 < r && r < x2)
xs.push_back(r);
sort(All(xs));
double res = 0;
Rep(i, Size(xs)-1) {
double x1 = xs[i], x2 = xs[i+1];
if (x1 > r-eps)
break;
double s1 = y1*(x2-x1), s2 = y2*(x2-x1);
double s4 = (0.5*x2*sqrt(sqr(r)-sqr(x2))+0.5*sqr(r)*asin2(x2/r))-(0.5*x1*sqrt(sqr(r)-sqr(x1))+0.5*sqr(r)*asin2(x1/r));
double s3 = -s4;
res += max(0.0, min(s2, s4)-max(s1, s3));
}
assert(res <= (x2-x1)*(y2-y1));
return res;
}

int main() {
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);

int t;
scanf("%d", &t);
For(test, 1, t) {
double f, R, t, r, g;
scanf("%lf%lf%lf%lf%lf", &f, &R, &t, &r, &g);
double sum = 0;
if (g > 2*f) {
double x = r;
while (x+f < R-t-f) {
double y = r;
while (sqrt(sqr(x+f)+sqr(y+f)) < R-t-f) {
sum += inters(x+f, y+f, x+g-f, y+g-f, R-t-f);
y += 2*r+g;
}
x += 2*r+g;
}
}
printf("Case #%d: %.6lf\n", test, (pi*sqr(R)-4*sum)/(pi*sqr(R)));
}

exit(0);
}



Everyone out there help me improve!!!

Google Code Jam Answer 2  

Posted by Unknown in ,

Again a bad answer by me. But was easy to write and correct in attempt 1:
Train Timetable
Problem

A train line has two stations on it, A and B. Trains can take trips from A to B or from B to A multiple times during a day. When a train arrives at B from A (or arrives at A from B), it needs a certain amount of time before it is ready to take the return journey - this is the turnaround time. For example, if a train arrives at 12:00 and the turnaround time is 0 minutes, it can leave immediately, at 12:00.

A train timetable specifies departure and arrival time of all trips between A and B. The train company needs to know how many trains have to start the day at A and B in order to make the timetable work: whenever a train is supposed to leave A or B, there must actually be one there ready to go. There are passing sections on the track, so trains don't necessarily arrive in the same order that they leave. Trains may not travel on trips that do not appear on the schedule.

Input

The first line of input gives the number of cases, N. N test cases follow.

Each case contains a number of lines. The first line is the turnaround time, T, in minutes. The next line has two numbers on it, NA and NB. NA is the number of trips from A to B, and NB is the number of trips from B to A. Then there are NA lines giving the details of the trips from A to B.

Each line contains two fields, giving the HH:MM departure and arrival time for that trip. The departure time for each trip will be earlier than the arrival time. All arrivals and departures occur on the same day. The trips may appear in any order - they are not necessarily sorted by time. The hour and minute values are both two digits, zero-padded, and are on a 24-hour clock (00:00 through 23:59).


After these NA lines, there are NB lines giving the departure and arrival times for the trips from B to A.


Output
For each test case, output one line containing "Case #x: " followed by the number of trains that must start at A and the number of trains that must start at B.

Limits

1 ≤ N ≤ 100

Small dataset

0 ≤ NA, NB ≤ 20

0 ≤ T ≤ 5

Large dataset

0 ≤ NA, NB ≤ 100

0 ≤ T ≤ 60

Sample
Input
2
5
3 2
09:00 12:00
10:00 13:00
11:00 12:30
12:02 15:00
09:00 10:30
2
2 0
09:00 09:01
12:00 12:02

Output
Case #1: 2 2
Case #2: 2 0

My answer - agin bad but I got a hold of OOPS

// train.cpp : Defines the entry polong int for the console application.
//

#include "stdafx.h"
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
class train
{
public:
long int presentstation;
long int availableafter;
long int turnaround;
public:
void reachstation(long int station,long int time)
{
presentstation = station;
availableafter = time+turnaround;
}
void settrain(long int tt)
{
turnaround = tt;
}

};
class time
{
public:
long int start;
long int end;
long int station;
public:
void settime(long int Station,char* time)
{
station =Station;
start = (time[0] - '0') *600 + (time[1] -'0')*60 + (time[3] - '0')*10 + (time[4]-'0');
end = (time[6] - '0') *600 + (time[7] -'0')*60 + (time[9] - '0')*10 + (time[10]-'0');
}
};
int comp(const void *A,const void *B)
{
time *p = (time*) A;
time *q = (time*) B;
return (int) (p->start - q->start);
}
long int main()
{
long int no =0;
cin>>no;
for(long int counter = 1; counter<=no;counter++)
{
printf("Case #%d: ",counter);
long int turnaround = 0;
long int NA,NB;
cin>>turnaround;
cin>>NA>>NB;
char useless[7];
if(NA+NB != 0 )
{gets_s(useless);
}
time Time[200];
train Train[200];
long int NoTrains = 0;
char a[100];
for(long int i=0;i<NA; i++)
{
gets_s(a);
Time[i].settime(0,a);
strcpy_s(a,"");
}
for(long int i=NA;i<(NB+NA); i++)
{
gets_s(a);
Time[i].settime(1,a);
}
qsort(Time,NA+NB,sizeof(time),&comp);
//printf("%d\t%d\t%d",Time[0].start,Time[1].start,Time[2].start);
long int flag;
long int startA=0,startB=0;
for(long int i=0; i<NA+NB; i++)
{
flag=0;
for(long int j=0;j<NoTrains; j++)
{
if((Train[j].availableafter <= Time[i].start) && (Train[j].presentstation == Time[i].station))
{
Train[j].reachstation(1-Time[i].station,Time[i].end);
flag=1;
break;
}
}
if(flag==0)
{
Train[NoTrains].settrain(turnaround);
Train[NoTrains].reachstation(1-Time[i].station,Time[i].end);
NoTrains++;
if(Time[i].station == 0)
startA++;
else
startB++;
}
}
printf("%d %d\n",startA,startB);

}
return 0;

}


and the great answer by rem


#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <ctime>
using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,int> pii;

#define _CRT_SECURE_NO_WARNINGS
#define For(i,a,b) for (int i(a),_b(b); i <= _b; ++i)
#define Ford(i,a,b) for (int i(a),_b(b); i >= _b; --i)
#define Rep(i,n) for (int i(0),_n(n); i < _n; ++i)
#define Repd(i,n) for (int i((n)-1); i >= 0; --i)
#define Fill(a,c) memset(&a, c, sizeof(a))
#define MP(x, y) make_pair((x), (y))
#define All(v) (v).begin(), (v).end()

template<typename T, typename S> T cast(S s) {
stringstream ss;
ss << s;
T res;
ss >> res;
return res;
}

template<typename T> inline T sqr(T a) { return a*a; }
template<typename T> inline int Size(const T& c) { return (int)c.size(); }
template<typename T> inline void checkMin(T& a, T b) { if (b < a) a = b; }
template<typename T> inline void checkMax(T& a, T b) { if (b > a) a = b; }

int readTime() {
int h, m;
scanf("%d:%d", &h, &m);
return m+60*h;
}

int main() {
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);

int t;
scanf("%d", &t);
For(test, 1, t) {
int t;
scanf("%d", &t);
int n1, n2;
scanf("%d%d", &n1, &n2);
vector<pii> t1(n1), t2(n2);
Rep(i, n1) {
t1[i].first = readTime();
t1[i].second = readTime();
}
Rep(i, n2) {
t2[i].first = readTime();
t2[i].second = readTime();
}
sort(All(t1));
sort(All(t2));
int r1 = 0, r2 = 0;
while (Size(t1) > 0 || Size(t2) > 0) {
int x;
if (Size(t2) > 0 && (Size(t1) == 0 || t2[0] < t1[0])) {
++r2;
x = t2[0].second;
t2.erase(t2.begin());
} else {
++r1;
x = -t;
}
for (;;) {
int i = 0;
while (i < Size(t1) && t1[i].first < x+t)
++i;
if (i == Size(t1))
break;
x = t1[i].second;
t1.erase(t1.begin()+i);
i = 0;
while (i < Size(t2) && t2[i].first < x+t)
++i;
if (i == Size(t2))
break;
x = t2[i].second;
t2.erase(t2.begin()+i);
}
}
printf("Case #%d: %d %d\n", test, r1, r2);
}

exit(0);
}

See how much I need to improve answer 3 in next post

Google code Jam : i am not a contest programmer  

Posted by Unknown in ,

I may be among the best programmers of my batch in my college but definitely I am not worth calling myself as a programmer. I am far from a standard contest programmer for my programs are still those written on college papers. Plus I am still new to the STl and the contest world. i have just had a few outings. But I plan to have massive changes to this state this year. I have started with the google code jam, a big programming contest popularised by google for programmer's all over the world. The contest had its qualifiers on thursday and indeed as said qualifiers are for only to sort out people who don't know what programming is, it came out. The first question was sort of easy and so was the second one( Even i could do that). But the third one was gud. Just not really as an article I write this posting to my blog to help me trace if i can improve as a programmaer this year. You can expect to see top coder contest codes to be here as well, for I just joined that.
Here is the link to the files Ques+Mine as well as ideal answers + Hope I see this next year:http://w14.easy-share.com/1700957331.html
I have converted the cpp to html. I have used a project at codeproject. The files are at:http://w14.easy-share.com/1700966549.html
So now I can paste the stuff here:
Saving the universe
Problem

The urban legend goes that if you go to the Google homepage and search for "Google", the universe will implode. We have a secret to share... It is true! Please don't try it, or tell anyone. All right, maybe not. We are just kidding.

The same is not true for a universe far far away. In that universe, if you search on any search engine for that search engine's name, the universe does implode!

To combat this, people came up with an interesting solution. All queries are pooled together. They are passed to a central system that decides which query goes to which search engine. The central system sends a series of queries to one search engine, and can switch to another at any time. Queries must be processed in the order they're received. The central system must never send a query to a search engine whose name matches the query. In order to reduce costs, the number of switches should be minimized.

Your task is to tell us how many times the central system will have to switch between search engines, assuming that we program it optimally.

Input

The first line of the input file contains the number of cases, N. N test cases follow.

Each case starts with the number S -- the number of search engines. The next S lines each contain the name of a search engine. Each search engine name is no more than one hundred characters long and contains only uppercase letters, lowercase letters, spaces, and numbers. There will not be two search engines with the same name.

The following line contains a number Q -- the number of incoming queries. The next Q lines will each contain a query. Each query will be the name of a search engine in the case.

Output

For each input case, you should output:
Case #X: Y
where X is the number of the test case and Y is the number of search engine switches. Do not count the initial choice of a search engine as a switch.


Limits

0 <>Input
2
5
Yeehaw
NSM
Dont Ask
B9
Googol
10
Yeehaw
Yeehaw
Googol
B9
Googol
NSM
B9
NSM
Dont Ask
Googol
5
Yeehaw
NSM
Dont Ask
B9
Googol
7
Googol
Dont Ask
NSM
NSM
Yeehaw
Yeehaw
Googol

Output
Case #1: 1
Case #2: 0

So here is what I managed: Not good but i need to keep a track of myself.



// savetheuniverse.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"
#include<iostream>
#include<string.h>
#include<conio.h>
#include<stdio.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int no =0;
cin>>no;
for(int counter = 1; counter<=no;counter++)
{
printf("Case #%d: ",counter);
int NoOfEngines = 0;
cin>>NoOfEngines;
char useless[7];
if(NoOfEngines != 0 )
gets_s(useless);
//cout<<NoOfEngines<<endl;
char Eng[1000][100];
int CalledEng[1000] = {0};
for (int Engine = 0;Engine<NoOfEngines;Engine++)
{
gets_s(Eng[Engine]);
//cout<<Eng[Engine]<<endl;
}
int NoOfSearches;
cin>>NoOfSearches;
//cout<<NoOfSearches<<endl;
if(NoOfSearches != 0 )
gets_s(useless);
char Sear[1000][100];
for(int Search = 0;Search <NoOfSearches; Search++)
{
gets_s(Sear[Search]);
//cout<<Sear[Search]<<endl;
}

int Present = 1;
int LastElementIndex=0;
while(1)
{

for(int i=LastElementIndex;i<NoOfSearches;i++)
{
for(int j=0;j<NoOfEngines;j++)
{
if(strcmp(Sear[i],Eng[j]) == 0)
{

if(CalledEng[j] != Present)
{
CalledEng[j] =Present;
LastElementIndex = i;
}
break;
}
}
}
//if(counter==8)
//printf("%d\t%d\n",Present,LastElementIndex);
int flag=0;
for(int i=0;i<NoOfEngines;i++)
{
if(CalledEng[i]<Present) {flag =1 ;}
}
if(flag==1) {break;}
Present++;
if(LastElementIndex >= NoOfSearches-1) break;
}
printf("%d\n",Present-1);
}
return 0;
}



And this was the ideal answer

#include <map>

#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <ctime>
using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;

#define _CRT_SECURE_NO_WARNINGS
#define For(i,a,b) for (int i(a),_b(b); i <= _b; ++i)
#define Ford(i,a,b) for (int i(a),_b(b); i >= _b; --i)
#define Rep(i,n) for (int i(0),_n(n); i < _n; ++i)
#define Repd(i,n) for (int i((n)-1); i >= 0; --i)
#define Fill(a,c) memset(&a, c, sizeof(a))
#define MP(x, y) make_pair((x), (y))
#define All(v) (v).begin(), (v).end()

template<typename T, typename S> T cast(S s) {
stringstream ss;
ss << s;
T res;
ss >> res;
return res;
}

template<typename T> inline T sqr(T a) { return a*a; }
template<typename T> inline int Size(const T& c) { return (int)c.size(); }
template<typename T> inline void checkMin(T& a, T b) { if (b < a) a = b; }
template<typename T> inline void checkMax(T& a, T b) { if (b > a) a = b; }

char buf[1024*1024];

int main() {
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);

gets(buf);
For(test, 1, atoi(buf)) {
int s, q;
map<string,int> num;
gets(buf);
s = atoi(buf);
Rep(i, s) {
gets(buf);
num[buf] = i;
}
gets(buf);
q = atoi(buf);
vi dp(s, 0);
Rep(i, q) {
gets(buf);
assert(num.count(buf) > 0);
int id = num[buf];
Rep(j, s)
if (j != id)
checkMin(dp[j], dp[id]+1);
dp[id] = 1000000;
}
printf("Case #%d: %d\n", test, *min_element(All(dp)));
}

exit(0);
}

I'll write answer 2 and 3 in a seperate post