TCS
Company
Programming
Rotation
A Game developer is developing a game. To enrich his graphics he needs a quick API to do rotation and scaling of objects of various shapes that appear in the game. You have been chosen to partner this developer. Shoulder the responsibility of developing this API.
You have your work cut-out in form of the input and output specs below.
Input Format:
First line contains number of sides of a polygon, denoted by N
Next N lines contain x and y coordinates, respectively, of the points forming the polygon, delimited by space
Next line contains angle of rotation A
Next line contains scaling factor S
Last line contains coordinates about which the polygon has to be rotated, denoted by (a, b)
Output Format:
Print new coordinates of polygon after rotation and scaling
Constraints:
Polygon will be 3-sided or higher
x and y can be positive or negative integers or zero
Angle of rotation (A) can have only three discrete values {90, 180, 270} in degree
Positive angles indicate clock-wise rotation. Negative angles indicate anti clock-wise rotation
Scaling Factor S can be greater than 1
Point around which the polygon has to be rotated, denoted by (a, b) can be positive or negative integers or zero
Read Solution (Total 0)
TCS Other Question
Matrix Power
Alice is learning basic discrete mathematics. In between of her leanings one day her tutor has given the following problem.
"A^M = A*A*A ... M times."
Let K be the matrix with N*N size and Aij represent the element at ith row and jth column. Matrix exponent product is defined as . As the result can be long mod the result with 1000000007.
As the Alice is newbie to maths, help her to solve the problem.
Input Format:
First line starts with N, and then N lines follow each will contain N spaced integers Aij.
After N lines next line contains M.
Output Format:
Print the matrix exponent product.
Constraints:
1<=N<=4000
1<=Aij<=10^7
1<=M<=10^9
Grandpa's Candy Distribution
Rahul is considered to be the luckiest kid around, by his classmates - his grandpa has a candy factory! And the factory produces a thousand different flavours of candies!
Rahul's birthday is around the corner and the entire school is excited to receive the candies. Rahul approaches his grandpa and asks for candies to be distributed on his birthday.
His grandpa tasks him with a problem - he says that he will give him as many candies as he wants (N) of all distinct flavours for as many students in his school (K) if he can tell him the sum of the following:
The number of ways there are to choose K/2 candies out of N/2 disregarding the order of selection, and
The number of ways there are to choose K/2 candies out of N/2 taking into account the order of selection.
Give the answer, modulo 1000000007. Assume integer division while halving N and K.
Input Format:
First line contains a positive integer T determining the number of test cases
Next T lines contain two positive integers each, viz. N and K separated by white space.
Output Format:
For each test case, print a single integer per line denoting the sum of total number of ways to distribute N candies among K students as per grandpa's method, modulo 1000000007
Constraints:
1 <=T <= 1,000,000
2 <=N <=2000
2 <=K <=1000