Một số khái niệm về lập trình và ngôn ngữ lập trình

Quỳnh Anh
Xem chi tiết
Quỳnh Anh
8 tháng 11 2021 lúc 22:06

Giúp mình với Kudo Shinichi AKIRA^_^

Bình luận (0)
Nguyễn Lê Phước Thịnh
8 tháng 11 2021 lúc 23:13

Chọn B

Bình luận (0)
Minh Lệ
27 tháng 10 2021 lúc 6:15

Câu 1:

a) ((-5)<=x) and (x<=5);

b) abs(1+x)-(5*sqr(x)+3)/((sqr(x)+3)/(2*x+4));

Câu 2:

Program HOC24;

var s,r: real;

begin

write('Nhap ban kinh: '); readln(r);

s:=r*r*pi;

write('Dien tich hinh tron la: ',s:1:2);

readln

end.

Bình luận (0)
RealBoyMC
Xem chi tiết
Tran Nguyễn Đăng Dương
16 tháng 10 2021 lúc 16:59

C. False

50 không bằng 49 nên (50==49) có giá trị là False (còn tại sao là False mà ko false thì cái đó là do Python nó như vậy)

(ko biết giải thích như vậy có đúng ko do mình giải thích theo cách mình hiểu)

Bình luận (0)
Trần Việt Đức
2 tháng 10 2021 lúc 21:55

Bình luận (1)
Nguyễn trọng toàn
Xem chi tiết
Minh Lệ
1 tháng 10 2021 lúc 21:55

Program HOC24;

var i,n,x: integer

fx,f: longint;

begin

write('Nhap x: '); readln(x);

fx:=1;

for i:=1 to 10 do

begin

fx:=fx*x;

if i=5 then f:=fx;

end;

fx:=fx+f+1;

write('f(',x,')=',fx);

readln

end.

Bình luận (0)
Quốc Khánh Minh
26 tháng 8 2021 lúc 9:19

 ngôn ngữ python ạ

 

Bình luận (1)
Tran Nguyễn Đăng Dương
28 tháng 8 2021 lúc 18:45

Py thì khó giúp rồi, do phần lớn dân trên đây dùng Pas/C++

Để cố làm thử xem sao

Trong lúc đó thì mình xin nói thuật toán 

Vì n và s[i]<32000 nên ta có thể dùng map để lưu giữ các số (còn ko thì cho dãy arr[32000] trong đó arr[i] là số lần i xuất hiện)

Từ đó bạn có thể for qua dãy để tìm các arr[i]>1, rồi xuất i

Bình luận (0)
Anh Phạm
31 tháng 7 2021 lúc 19:58

#include <bits/stdc++.h>
#define forvct(i,v) for(int i = 0, _key = v.size(); i < _key; ++i)
#define forinc(i,a,b) for(int i = a, _key = b; i <= _key; ++i)
#define fordec(i,a,b) for(int i = a, _key = b; i >= _key; --i)
#define p_b push_back
#define ll long long
#define nn 100001

using namespace std;

int n, m, l, q, t, res, test,
    a[nn], tin[nn], tout[nn], mark[nn], terror[nn], p[nn][20];
vector<int> adj[nn], _adj[nn];
stack<int> stk;

void enter()
{
    cin >> n;
    int u, v;
    forinc(i,1,n-1)
    {
        cin >> u >> v;
        adj[u].p_b(v);
        adj[v].p_b(u);
    }
    l = log2(n);
    cin >> q;
}

void visit(const int &u)
{
    tin[u] = ++t;
    forinc(j,1,l) p[u][j] = p[p[u][j-1]][j-1];
    forvct(j,adj[u])
    {
        int v = adj[u][j];
        if (v != p[u][0])
        {
            p[v][0] = u;
            visit(v);
        }
    }
    tout[u] = ++t;
}

bool anc(const int &u, const int &v)
{
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}

int lca(int u, int v)
{
    if (anc(u,v)) return u;
    if (anc(v,u)) return v;
    fordec(j,l,0)
        if (!anc(p[u][j],v)) u = p[u][j];
    return p[u][0];
}

bool cmp(const int &x, const int &y)
{
    return tin[x] < tin[y];
}

bool check(const int &u)
{
    int cnt = 0;
    forvct(j,_adj[u])
    {
        int v = _adj[u][j];
        if (terror[u] == test)
        {
            if (terror[v] == test && p[v][0] == u)
            {
                res = -1;
                return -1;
            }
            bool x = check(v);
            if (res == -1) return -1;
            res += x;
        }
        else
        {
            bool x = check(v);
            if (res == -1) return -1;
            cnt += x;
        }
    }
    if (terror[u] == test || cnt == 1) return 1;
    if (cnt > 1) res++;
    return 0;
}

void query()
{
    cin >> m;
    forinc(i,1,m)
    {
        cin >> a[i];
        _adj[a[i]].clear();
        mark[a[i]] = test;
        terror[a[i]] = test;
    }
    sort(a+1,a+m+1,cmp);
    forinc(i,1,m-1)
    {
        int tmp = lca(a[i],a[i+1]);
        if (mark[tmp] < test)
        {
            mark[tmp] = test;
            a[++m] = tmp;
            _adj[tmp].clear();
        }
    }
    sort(a+1,a+m+1,cmp);
    while (!stk.empty()) stk.pop();
    stk.push(a[1]);
    forinc(i,2,m)
    {
        while (tout[stk.top()] < tout[a[i]]) stk.pop();
        _adj[stk.top()].p_b(a[i]);
        stk.push(a[i]);
    }
    res = 0;
    check(a[1]);
    cout << res << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    enter();
    p[1][0] = 1;
    visit(1);
    for(test = 1; test <= q; ++test) query();
}

 

Bình luận (0)
Anh Phạm
31 tháng 7 2021 lúc 19:59

#include <bits/stdc++.h>

using namespace std;

const int maxn = 100010;

vector<int> edge[maxn];
int f[maxn];
bool visited[maxn];

void dfs(int u) {
  visited[u] = true;
  f[u] = 1;
  for (int v : edge[u]) {
    if (!visited[v]) {
      dfs(v);
      f[u] += f[v];
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  vector<int> components;
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      dfs(i);
      components.push_back(f[i]);
    }
  }
  int res = components.front();
  int rest = 0;
  for (int i = 1; i < components.size(); i++) {
    rest = max(rest, components[i]);
  }
  cout << res + rest << endl;
}

 

Bình luận (0)
Trần Minh Hoàng
27 tháng 7 2021 lúc 11:39

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t,n,a[100001],s[100001],Max,sum,Min[100001],Max2;
    cin >> t;
    for (int i=1;i<=t;i++)
    {
        Max=INT_MIN;
        sum=0;
    cin >> n;
    s[0]=0;
    Min[0]=0;
    Max2=a[1];
    for (int i=1;i<=n;i++)
        {
            cin >> a[i];
            s[i]=s[i-1]+a[i];
            if (a[i]>Max) Max=a[i];
            if (a[i]>0) sum+=a[i];
            Min[i]=min(Min[i-1],s[i]);
            Max2=max(Max2,s[i]-Min[i-1]);
        }
    if (sum==0) cout << Max;
    else cout << sum;
    cout << ' ' << Max2 << '\n'
    }
    return 0;

}

Bình luận (2)
Anh Phạm
31 tháng 7 2021 lúc 20:01

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100005;
const int oo = 1000000007;

int nTest, n, a[MAXN];

int task1() {
    int res = 0;
    bool allNegative = true;

    for(int i = 0; i < n; ++i) {
        if (a[i] >= 0) {
            allNegative = false;
            res += a[i];
        }
    }

    if (allNegative)
        res = *max_element(a, a+n);
    return res;
}

int task2() {
    int sum = 0, res = -oo;
    for(int i = 0; i < n; ++i) {
        sum = sum + a[i];
        res = max(res, sum);
        sum = max(sum, 0);
    }

    return res;
}

int main() {
    scanf("%d", &nTest);
    while (nTest--) {
        scanf("%d", &n);
        for(int i = 0; i < n; ++i)
            scanf("%d", &a[i]);

        printf("%d %d\n", task1(), task2());
    }

}

Bình luận (0)
Phạm Hoài An
Xem chi tiết