Programming tasks - Solutions

I won't explain my codes. I just post it to help you, when you are testing your code. Here you can see the tasks.

Moon

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > table;
vector<int> bin;
int extend(int y, int x, int r);
int power(int a){return a*a;}
int w,h;
int main()
{
    cin >> w >> h;
    bin.resize(w,0);
    table.resize(h,bin);
    char input_helper;
    int x=0,y=0,r=-1;
    for(int a=0;a<h;a++)
        for(int b=0;b<w;b++){
            cin >> input_helper;
            table[a][b]=(input_helper=='.')?0:1;
        }
    int center[h][w];
    for(int a=0;a<h;a++){
        for(int b=0;b<w;b++){
            if(table[a][b]==0){
                center[a][b] = -1;
                continue;
            }
            else{
                center[a][b]=1+extend(a,b,1);
                r=(r>center[a][b])?r:center[a][b];
            }
        }
    }
    for(y=0;y<h;y++)
        for(x=0;x<w;x++)
            if(center[y][x]==r){
                cout << r-1 << endl << x+1 << " " << y+1;
                return 0;
            };
    return 0;
}
int extend(int y, int x, int r){
    if(x-r<0||x+r>=w||y-r<0||y+r>=h)  return 0;
    for(int a=x-r;a<=x+r;a++){
        for(int b=y+r;b>=y-r;b--){
            if(table[b][a]==1)  continue;
            if(power(a-x)+power(b-y)<=power(r)) return 0;
        }
    }
    return 1+extend(y,x,r+1);
}

Factorisation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <vector>
using namespace std;
typedef long long int longint;
vector<longint> first;
vector<longint> second;
vector<longint> solution;
const longint minimum=2;
longint maximum=1000000;
int main()
{
    first.resize(maximum+1,0);
    second.resize(maximum+1,0);
    for(int a=minimum;a<=maximum;a++){
        if(second[a]==-1)   continue;
        for(int b=a;b<=maximum;b+=a){
            first[b]++;
            second[b]=(second[b]==-1)?-1:(second[b]==0)?a:(a%second[b]==0)?second[b]:-1;
        }
    }
    for(int a=minimum;a<=maximum;a++){
        if(first[a]>=solution.size()) solution.resize(first[a]+1,0);
        solution[first[a]]++;
    }
    for(int a=1;a<solution.size();a++)
        cout << solution[a] << endl;
    return 0;
}

Note by Páll Márton
1 week, 1 day ago

No vote yet
1 vote

  Easy Math Editor

This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.

When posting on Brilliant:

  • Use the emojis to react to an explanation, whether you're congratulating a job well done , or just really confused .
  • Ask specific questions about the challenge or the steps in somebody's explanation. Well-posed questions can add a lot to the discussion, but posting "I don't understand!" doesn't help anyone.
  • Try to contribute something new to the discussion, whether it is an extension, generalization or other idea related to the challenge.
  • Stay on topic — we're all here to learn more about math and science, not to hear about your favorite get-rich-quick scheme or current world events.

MarkdownAppears as
*italics* or _italics_ italics
**bold** or __bold__ bold

- bulleted
- list

  • bulleted
  • list

1. numbered
2. list

  1. numbered
  2. list
Note: you must add a full line of space before and after lists for them to show up correctly
paragraph 1

paragraph 2

paragraph 1

paragraph 2

[example link](https://brilliant.org)example link
> This is a quote
This is a quote
    # I indented these lines
    # 4 spaces, and now they show
    # up as a code block.

    print "hello world"
# I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
MathAppears as
Remember to wrap math in \( ... \) or \[ ... \] to ensure proper formatting.
2 \times 3 2×3 2 \times 3
2^{34} 234 2^{34}
a_{i-1} ai1 a_{i-1}
\frac{2}{3} 23 \frac{2}{3}
\sqrt{2} 2 \sqrt{2}
\sum_{i=1}^3 i=13 \sum_{i=1}^3
\sin \theta sinθ \sin \theta
\boxed{123} 123 \boxed{123}

Comments

There are no comments in this discussion.

×

Problem Loading...

Note Loading...

Set Loading...