177 条题解

  • -2
    @ 2024-6-9 21:34:09
    #include <bits/stdc++.h>
    using namespace std;
    const int N = 1e4 + 15, M = 2e5 + 10;
    
    vector<int> edge[N];
    int h[N], e[M], ne[M], idx, p[N];
    int in[N];
    int n, m;
    void add(int a, int b) {
        e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
        in[b]++;
    }
    
    int dfn[N], low[N], tot = 0;
    stack<int> stk;
    bool st[N];
    int sz[N], scc[N], color;
    
    void tarjan(int u) {
        dfn[u] = low[u] = ++tot;
        stk.push(u); st[u] = true;
        for (int v : edge[u]) {
            if (!dfn[v]) tarjan(v), low[u] = min(low[u], low[v]);
            else if (st[v]) low[u] = min(low[u], dfn[v]);
        }
        if (dfn[u] == low[u]) {
            ++color;
            while (stk.top() != u) {
                scc[stk.top()] = color;
                st[stk.top()] = false; stk.pop();
            }
            scc[stk.top()] = color;
            st[stk.top()] = false; stk.pop();
        }
    }
    
    queue<int> q;
    int dp[N];
    void topsort() {
        for (int i = 1; i <= color; i++) {
            dp[i] = sz[i];
            if (in[i] == 0) q.push(i);
        }
        while (q.size()) {
            int u = q.front(); q.pop();
            for (int i = h[u]; ~i; i = ne[i]) {
                int v = e[i];
                dp[v] = max(dp[v], dp[u] + sz[v]); in[v]--;
                if (in[v] == 0) q.push(v);
            }
        }
        int ans = 0;
        for (int i = 1; i <= color; i++) ans = max(ans, dp[i]);
        printf("%d\n", ans);
    }
    
    int main() {
        memset(h, -1, sizeof h);
        n = 2, m = 1;
        for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
        while (m--) {
            int a = 1, b = 2;
            edge[a].push_back(b);
        }
        for (int i = 1; i <= n; i++)
            if (!dfn[i]) tarjan(i);
        for (int i = 1; i <= n; i++) {
            sz[scc[i]] += p[i];
            for (int j : edge[i])
                if (scc[i] != scc[j]) add(scc[i], scc[j]);
        }
        topsort();
        return 0;
    }
    

    转自AcWing@Conan15

    • -2
      @ 2024-5-19 21:03:56

      A+B作为一道基础题,思维也很简单 看代码:

      #include <bits/stdc++.h>
      #define endl '\n'
      #define int long long
      
      using namespace std;
      
      signed main()
      {
      	int a, b;
      	cin >> a >> b;
      	cout << a + b; 
      	
      	return 0;
      }
      
      • -2
        @ 2024-4-14 8:31:48

        #include<bits/stdc++.h> using namespace std; int a,b; int main(){ cin>>a>>b; cout<<a+b<<endl; return 0; }//基础题

        • -2
          @ 2024-4-14 8:31:46

          #include<bits/stdc++.h> using namespace std; int a,b; int main(){ cin>>a>>b; cout<<a+b<<endl; return 0; }//基础题

          • -2
            @ 2024-4-6 11:58:55

            经典的 a+ba+b

            • -2
              @ 2024-4-5 20:01:38
              #include
              using namespace std;
              
              struct Node
              {
              int data;
              Node *prev;
              Node *next;
              Node(int val) : data(val), prev(nullptr), next(nullptr) {}
              };
              
              Node *createList(int num)
              {
              Node *head = nullptr;
              Node *tail = nullptr;
              while (num > 0)
              {
              int digit = num % 10;
              Node *newNode = new Node(digit);
              if (head == nullptr)
              {
              head = newNode;
              tail = newNode;
              }
              else
              {
              newNode->next = head;
              head->prev = newNode;
              head = newNode;
              }
              num /= 10;
              }
              return head;
              }
              
              Node *addTwoNumbers(Node *num1, Node *num2)
              {
              Node *result = nullptr;
              Node *current = nullptr;
              int carry = 0;
              

              while (num1 != nullptr || num2 != nullptr || carry != 0) { int sum = carry;

              if (num1 != nullptr)
              {
                  sum += num1->data;
                  num1 = num1->next;
              }
              
              if (num2 != nullptr)
              {
                  sum += num2->data;
                  num2 = num2->next;
              }
              
              carry = sum / 10;
              sum %= 10;
              
              Node *newNode = new Node(sum);
              
              if (result == nullptr)
              {
                  result = newNode;
                  current = newNode;
              }
              else
              {
                  current->prev = newNode;
                  newNode->next = current;
                  current = newNode;
              }
              

              }

              return result;

              }
              
              void printList(Node *head)
              {
              if (head == nullptr)
              {
              cout << "Empty list" << endl;
              return;
              }
              

              while (head != nullptr) { cout << head->data; head = head->next; } cout << endl;

              }
              
              void deleteList(Node *head)
              {
              while (head != nullptr)
              {
              Node *temp = head;
              head = head->next;
              delete temp;
              }
              }
              
              int main()
              {
              int num1 = 12345;
              int num2 = 6789;
              

              Node *list1 = createList(num1); Node *list2 = createList(num2);

              cout << "Number 1: "; printList(list1);

              cout << "Number 2: "; printList(list2);

              Node *sumList = addTwoNumbers(list1, list2);

              cout << "Sum: "; printList(sumList);

              deleteList(list1); deleteList(list2); deleteList(sumList);

              return 0;

              }
              
              
              • -2
                @ 2024-3-31 15:19:44
                #include <stdio.h>  #头文件  
                int main(){  #主函数
                    int a, b;  #申请int类型变量a,b
                    scanf("%d%d", &a, &b);#输入
                    printf("%d\n", a+b);#输出
                    return 0;#完美结束
                }
                
                • -2
                  @ 2024-3-17 11:28:00

                  #include<bits/stdc++.h> using namespace std; long long m,n;//一定要用long long 不然会错! int main(){ cin>>n>>m; cout<<n+m<<endl; } 管理大大求过qwq

                  • -2
                    @ 2024-3-17 11:26:22

                    #include<bits/stdc++.h> using namespace std; long long m,n; int main(){ cin>>n>>m; cout<<n+m<<endl; }

                    • -2
                      @ 2023-8-31 23:04:01

                      C++ 式普通写法

                      #include<iostream>
                      
                      using namespace std;
                      
                      int a,b;
                      
                      int main(){
                        cin >> a >> b;
                        cout << a + b;
                        return 0;
                      }
                      

                      高精度

                      #include<iostream>
                      
                      using namespace std;
                      
                      const int MAXN = 1e5 + 10;
                      
                      long long r;
                      int c;
                      char op;
                      
                      struct bigint{
                        long long len,sz[MAXN] = {0};
                      
                        long long &operator [] (long long a){
                          return sz[a];
                        }
                      
                        void input(){
                          string s;
                          cin >> s;
                          len = s.size();
                          for (int i = 0; i < len; i++){
                            sz[i] = s[len - i - 1] - '0';
                          }
                        }
                      
                        void output(){
                          for (; len - 1 > 0 && !sz[len - 1]; len--){
                          }
                      
                          for (int i = len - 1; i >= 0; i--){
                            cout << sz[i];
                          }
                          cout << '\n';
                        }
                        bigint operator + (const bigint &b){
                          bigint c;
                          c.len = max(len,b.len) + 1;
                          for (int i = 0; i < c.len; i++){
                            c[i] = sz[i] + b.sz[i];
                          }
                      
                          for (int i = 0; i < c.len - 1; i++){
                            c[i + 1] += c[i] / 10,c[i] %= 10;
                          }
                          return c;
                        }
                      }a,b,ans;
                      
                      int main(){
                        a.input(),b.input();
                        ans = a + b;
                        ans.output();
                        return 0;
                      }
                      
                      • -2
                        @ 2023-2-26 10:43:36

                        CODE:

                        #include<bits/stdc++.h>
                        using namespace std;
                        
                        int main()
                        {
                            int a,b;cin>>a>>b;cout<<a+b<<endl;
                            return 0;
                        }
                        

                        求赞!

                        • -2
                          @ 2023-1-4 22:36:13
                          #include<stdio.h>
                          int main()
                          {
                              int a,b;
                              scanf("%d%d",&a,&b);
                              printf("%d",a+b);
                              return 0;
                          }
                          
                          • -2
                            @ 2022-12-31 16:20:38
                            #include<iostream> //头文件
                            using namespace std; //命名空间
                            int main(){ //主函数,程序从这里开始
                                int a,b; //定义变量
                                cin>>a>>b; //输入
                                cout<<a+b<<endl; //输出他们的和
                                return 0; //主函数需要返回0
                            }
                            
                            
                            • -2
                              @ 2022-12-29 10:55:08

                              非常简单的一道题,代码:

                              var a,b:longint;
                              begin
                                  readln(a,b);
                                  write(a+b);
                              end.
                              

                              注意pascal用integer会爆掉。

                              • -2
                                @ 2022-12-7 21:28:42
                                #include <iostream> //头文件
                                
                                using namespace std; //如果没有这一句,将无法正常使用cin, cout;
                                
                                int main () { //主函数
                                    int a, b; //定义,c++的变量必须先定义才能使用
                                    cin >> a >> b; //输入,相当于键入赋值
                                    cout << a + b << endl; //输出,endl指换行
                                    return 0; //结束程序
                                }
                                
                                • -2
                                  @ 2022-12-3 11:34:28
                                  #include<bits/stdc++.h>
                                  using namespace std;
                                  int main(){
                                       int a,b;
                                       scanf("%d%d",&a,&b);
                                       return !printf("%d",a+b);
                                  }
                                  
                                  • -2
                                    @ 2022-11-22 16:02:23
                                    #include <bits/stdc++.h>
                                    using namespace std;int a,b;int main(){cin>>a>>b;cout<<a+b<<endl;return 0;}
                                    
                                    • -2
                                      @ 2022-11-20 18:23:45

                                      非常简单的一道题,输出a+b的和即可。

                                      代码:

                                      #include<cstdio>//C语言风格输入输出头文件
                                      int main(){ //主函数
                                          int a,b;//定义变量
                                          scanf("%d%d",&a,&b);//输入a和b
                                          printf("%d",a+b);//输出a+b
                                          return 0; //返回值
                                      }
                                      
                                      • -2
                                        @ 2022-6-19 11:30:22

                                        补充一个julialang题解

                                        a=parse(Int, readuntil(stdin, ' '))
                                        b=parse(Int, readline())
                                        print(a+b)
                                        
                                        • -2
                                          @ 2022-5-29 14:48:53

                                          好吧,同志们,我们就从这一题开始,向着大牛的路进发。 任何一个伟大的思想,都有一个微不足道的开始。

                                          #include<bits/stdc++.h>//万能头文件
                                          using namespace std;//使用标准命名空间
                                          int a,b;//定义整型变量a、b,也就是参与运算的两个数
                                          int main(){//主函数,程序在这里运行
                                              cin>>a>>b;//标准输入
                                              cout<<a+b;//标准输出
                                              return 0;//返回值,主函数的返回值必须是0
                                          }
                                          

                                          信息

                                          ID
                                          56
                                          时间
                                          1000ms
                                          内存
                                          1024MiB
                                          难度
                                          1
                                          标签
                                          递交数
                                          10363
                                          已通过
                                          4682
                                          上传者