Please help me write this program! We can write this code in either Python 3, C+
ID: 3871511 • Letter: P
Question
Please help me write this program!
We can write this code in either Python 3, C++, or in Java but I feel that it will be easier and shorter in Python 3. Please help me write this code and also help me answer the questions. Also, please try to make the result of the code have two graphs as shown in the examples below. Thank You! Please provide screenshots of your code for the formatting.
Assume you live in London in 1940. As the German Luftwaffe continue their nightly bombings of the city, you become worried a bomb might land on your house while you sleep. To put your mind at rest you decide to figure out the probability of a bomb landing on your house. You take a sample space of 10 blocks by 10 blocks containing your house and receive intelligence that roughly 200 bombs are being dropped nightly in this area. Should you flee the city or take your chances staying home? (a) Create a 10-by-10 grid and specify which block your house is. (b) Simulate 200 bombs dropping in the 10-by-10 grid and run this simulation 4 times, recording the results for each. This simulates four nights of bombings. How many bombs landed in your block? How many bombs landed in each block? How many bombs can any one block expect to receive in a night? (c) Using a Poisson distribution, what is the predicted probability of a bomb hitting your house? What is the expected number of bombs to land in your block? Do these results match any or all of your simulations? ylts match any or all of your sin Submit: your code, graphs or data, and a short text file answering (c). Here are sample graphs of my experiment (red square represents my house)Explanation / Answer
for(int i = 1; i < temperatures.length; i++) {
temperatures[i] = (temperatures[i-1] + 12) / 2; //takes average of 12 and previous temp
}
}
public void paint(Graphics g) {
for(int y = 1; y < 9; y++) {
g.setColor(Color.black);
g.drawRect(10, 10, 10, 10);
g.drawRect(10, 10, 10, 20);
g.drawRect(10, 10, 10, 30);
g.drawRect(10, 10, 10, 40);
g.drawRect(10, 10, 10, 50);
g.drawRect(10, 10, 10, 60);
g.drawRect(10, 10, 10, 70);
g.drawRect(10, 10, 10, 80);
g.drawRect(10, 10, 10, 90);
g.drawRect(10, 10, 10, 100);
for(int x = 1; x < 9; x++) {
g.setColor(Color.black);
g.drawRect(10, 10, 10, 10);
g.drawRect(10, 10, 20, 10);
g.drawRect(10, 10, 30, 10);
g.drawRect(10, 10, 40, 10);
g.drawRect(10, 10, 50, 10);
g.drawRect(10, 10, 60, 10);
g.drawRect(10, 10, 70, 10);
g.drawRect(10, 10, 80, 10);
g.drawRect(10, 10, 90, 10);
g.drawRect(10, 10, 100, 10);
}
}
}
}
width=10;
height=10;
for(x=0;x<10;x++)
{
for(y=0;y<10;y++)
{
g.drawRect(x*width,y*height,width,height);
}
}
int width = totalWidth / 10;
int height= totalHeight / 10;
for(int row=0;row<10;row++){
for(int col=0;col<10;col++){
g.drawRect(row*width,col*height,width,height);
}
}
import java.awt.*;
02
import javax.swing.*;
03
import java.awt.event.*;
04
import java.awt.geom.*;
05
06
07
public class MineSweeper extends JPanel {
08
int x=10,y=10,w=80,h=30;
09
Color c = new Color((int)(Math.random() * 0xFFFFFF));
10
public void paint(Graphics g){
11
Graphics2D g2 = (Graphics2D) g;
12
setLayout(new GridLayout(10,10));
13
for(int i=0;i<100;i++){
14
g2.drawRect(x+10,y+30,w,h);
15
g2.drawRect(x+10,y+30,w,h);
16
g2.setPaint(c);
17
}
18
}
19
public static void main(String[] args) {
20
JFrame f= new JFrame();
21
f.setTitle("lab9");
22
f.setSize(200,200);
23
f.addWindowListener(new WindowAdapter() {
24
public void windowClosing(WindowEvent e) {
25
System.exit(0);
26
}
27
});
28
Container contentPane = f.getContentPane();
29
contentPane.add(new MineSweeper());
30
f.show();
31
}
32
33
}
#include <bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
int main()
{
int X,Y; //X:number of rows, Y: number of columns
X = Y = 10; //assuming 10X10 matrix
int Cost[X][Y];
F(i,0,X-1)
{
F(j,0,Y-1)
{
//Take input the cost of visiting cell (i,j)
cin>>Cost[i][j];
}
}
int MinCost[X][Y]; //declare the minCost matrix
MinCost[0][0] = Cost[0][0];
// initialize first row of MinCost matrix
F(j,1,Y-1)
MinCost[0][j] = MinCost[0][j-1] + Cost[0][j];
//Initialize first column of MinCost Matrix
F(i,1,X-1)
MinCost[i][0] = MinCost[i-1][0] + Cost[i][0];
//This bottom-up approach ensures that all the sub-problems needed
// have already been calculated.
F(i,1,X-1)
{
F(j,1,Y-1)
{
//Calculate cost of visiting (i,j) using the
//recurrence relation discussed above
MinCost[i][j] = min(MinCost[i-1][j],MinCost[i][j-1]) + Cost[i][j];
}
}
cout<<"Minimum cost from (0,0) to (X,Y) is "<<MinCost[X-1][Y-1];
return 0;
}
import java.util.*;
class Ans
{
public static void main(String[] args)
{
//to print five lines
for(int i=1; i<=5; i++)
{
//each line has 10 characters
for(int j=1; j<=10; j++)
{
//if first or last character
//then print 1
//1 will also get printed if
//j is i or 10-i+1 is j
if(j == 1 || j == 10 || j==i || 10-i+1==j)
System.out.print("1");
else
System.out.print("0");
}
System.out.print(" ");
}
}
}
#include <bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
int main()
{
int X,Y; //X:number of rows, Y: number of columns
X = Y = 10; //assuming 10X10 matrix
int NumWays[X][Y]; //declare the NumWays matrix
NumWays[0][0] = 1;
// initialize first row of NumWays matrix
F(j,1,Y-1)
NumWays[0][j] = 1;
//Initialize first column of NumWays Matrix
F(i,1,X-1)
NumWays[i][0] = 1;
//This bottom-up approach ensures that all the sub-problems needed
// have already been calculated.
F(i,1,X-1)
{
F(j,1,Y-1)
{
//Calculate number of ways visiting (i,j) using the
//recurrence relation discussed above
NumWays[i][j] = NumWays[i-1][j] + NumWays[i][j-1];
}
}
cout<<"Number of ways from(0,0) to (X,Y) is "<<NumWays[X-1][Y-1];
return 0;
}
#include <bits/stdc++.h>
#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define MAX 1005
int Boy1[MAX][MAX];
int Boy2[MAX][MAX];
int Girl1[MAX][MAX];
int Girl2[MAX][MAX];
using namespace std;
int main()
{
int N,M,ans,op1,op2;
scanf("%d%d",&N,&M);
int Workout[MAX][MAX];
ans = 0;
//Take input the calories burnt matrix
F(i,1,N)
F(j,1,M)
scanf("%d",&Workout[i][j]);
//Table for Boy's journey from start to meeting cell
F(i,1,N)
F(j,1,M)
Boy1[i][j] = max(Boy1[i-1][j],Boy1[i][j-1]) + Workout[i][j];
//Table for boy's journey from end to meet cell
RF(i,N,1)
RF(j,M,1)
Boy2[i][j] = max(Boy2[i+1][j],Boy2[i][j+1]) + Workout[i][j];
//Table for girl's journey from start to meeting cell
RF(i,N,1)
F(j,1,M)
Girl1[i][j] = max(Girl1[i+1][j],Girl1[i][j-1]) + Workout[i][j];
//Table for girl's journey from end to meeting cell
F(i,1,N)
RF(j,M,1)
Girl2[i][j] = max(Girl2[i-1][j],Girl2[i][j+1]) + Workout[i][j];
//Now iterate over all meeting positions (i,j)
F(i,2,N-1)
{
F(j,2,M-1)
{
//For the option 1
op1 = Boy1[i][j-1] + Boy2[i][j+1] + Girl1[i+1][j] + Girl2[i-1][j];
//For the option 2
op2 = Boy1[i-1][j] + Boy2[i+1][j] + Girl1[i][j-1] + Girl2[i][j+1];
//Take the maximum of two options at each position
ans = max(ans,max(op1,op2));
}
}
printf("%d",ans);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.