CG Assignment
CG Assignment
# Reading input
N = int(input().strip())
matrix = []
for _ in range(N):
matrix.append(list(map(int, input().split())))
# Reading input
P = int(input().strip())
points = []
for _ in range(P):
x, y = map(int, input().split())
points.append((x, y))
S = int(input().strip())
while True:
points.append((x1, y1))
if x1 == x2 and y1 == y2:
break
e2 = 2 * err
if e2 > -dy:
err -= dy
x1 += sx
if e2 < dx:
err += dx
y1 += sy
return points
# Reading input
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
problem 4:
You are given a grid representing a 2D plane with some cells filled.
Use the flood fill algorithm to color the connected region starting
from a given cell.
Input Format
The first line contains two integers N and M, the dimensions of the
grid.
The next N lines each contain M integers representing the grid.
The next line contains two integers x and y, the starting cell
coordinates.
The last line contains an integer C, the new color.
Input: 4 4 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 2
Constraints
1≤N,M≤100
0≤grid[i][j]≤9
0≤x
0≤y
0≤C≤9
Output Format
Sample Input 0
33
000
010
000
11
2
Sample Output 0
000
020
000
Code: def flood_fill(grid, x, y, new_color):
N = len(grid)
M = len(grid[0])
original_color = grid[x][y]
if original_color == new_color:
return grid
grid[x][y] = new_color
fill(x + 1, y)
fill(x - 1, y)
fill(x, y + 1)
fill(x, y - 1)
fill(x, y)
return grid
# Reading input
N, M = map(int, input().split())
grid = []
for _ in range(N):
grid.append(list(map(int, input().split())))
x, y = map(int, input().split())
new_color = int(input().strip())
Problem 5:
Generate and visualize the Mandelbrot set for a given range and
iteration limit.
Input Format
The first line contains four floats 𝑥min, 𝑥max, 𝑦min and
ymaxrepresenting the range of complex numbers.
The second line contains an integer I, the number of iterations.
Input: -2.0 2.0 -2.0 2.0 1000
Constraints
−2.0≤ xmin ,xma ,ymin,ymax ≤2.0
Output Format
Output: A 2D array representing the Mandelbrot set (pseudo-visual
representation)
Sample Input 0
3
22
22
22
22
0.5
Sample Output 0
Bezier Point at t = 0.5: (2.0, 2.0)
Code: #include <stdio.h>
*x_result = x_temp[0];
*y_result = y_temp[0];
}
int main() {
int n = 3;
double x[] = {2, 2, 2}; // x-coordinates of control points
double y[] = {2, 2, 2}; // y-coordinates of control points
double t = 0.5; // Parameter t