• AtCoder Beginner Contest 070 (A B C D)


    A - Palindromic Number

    Problem Statement

    You are given a three-digit positive integer N.
    Determine whether N is a palindromic number.
    Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.

    Constraints

    • 100N999
    • N is an integer.

    Input

    Input is given from Standard Input in the following format:

    N
    

    Output

    If N is a palindromic number, print Yes; otherwise, print No.


    Sample Input 1

    Copy
    575
    

    Sample Output 1

    Copy
    Yes
    

    N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.

    求n是否回文,水题。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main() {
     5     int n;
     6     cin >> n;
     7     if(n/100 == n%10) printf("Yes
    ");
     8     else printf("No
    ");
     9     return 0;
    10 }

    B - Two Switches

    Problem Statement

    Alice and Bob are controlling a robot. They each have one switch that controls the robot.
    Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.
    Bob started holding down his button C second after the start-up, and released his button D second after the start-up.
    For how many seconds both Alice and Bob were holding down their buttons?

    Constraints

    • 0A<B100
    • 0C<D100
    • All input values are integers.

    Input

    Input is given from Standard Input in the following format:

    A B C D
    

    Output

    Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.


    Sample Input 1

    Copy
    0 75 25 100
    

    Sample Output 1

    Copy
    50
    

    Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.
    Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.
    Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.

    求ab与cd的相同区间,没有就是0.

    1 #include <bits/stdc++.h>
    2 using namespace std;
    3 
    4 int main() {
    5     int a, b, c, d;
    6     cin >> a >> b >> c >> d;
    7     printf("%d
    ",max(0,min(b,d)-max(a,c)));
    8     return 0;
    9 }

    C - Multiple Clocks

    Problem Statement

    We have N clocks. The hand of the i-th clock (1iN) rotates through 360° in exactly Ti seconds.
    Initially, the hand of every clock stands still, pointing directly upward.
    Now, Dolphin starts all the clocks simultaneously.
    In how many seconds will the hand of every clock point directly upward again?

    Constraints

    • 1N100
    • 1Ti1018
    • All input values are integers.
    • The correct answer is at most 1018 seconds.

    Input

    Input is given from Standard Input in the following format:

    N
    T1
    :  
    TN
    

    Output

    Print the number of seconds after which the hand of every clock point directly upward again.


    Sample Input 1

    Copy
    2
    2
    3
    

    Sample Output 1

    Copy
    6
    

    We have two clocks. The time when the hand of each clock points upward is as follows:

    • Clock 1: 2, 4, 6, seconds after the beginning
    • Clock 2: 3, 6, 9, seconds after the beginning

    Therefore, it takes 6 seconds until the hands of both clocks point directly upward.

    求n个数的最小公倍数。

     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 
     5 ll gcd(ll x, ll y) {
     6     return y ? gcd(y, x%y): x;
     7 }
     8 ll low(ll x, ll y) {
     9     return y/gcd(x, y) * x;
    10 }
    11 int main() {
    12     int n;
    13     cin >> n;
    14     ll x = 1, y;
    15     while(n--) {
    16         cin >> y;
    17         x = low(x, y);
    18     }
    19     cout << x << endl;
    20     return 0;
    21 }

    D - Transit Tree Path

    Problem Statement

    You are given a tree with N vertices.
    Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N1 edges, where N is the number of its vertices.
    The i-th edge (1iN1) connects Vertices ai and bi, and has a length of ci.

    You are also given Q queries and an integer K. In the j-th query (1jQ):

    • find the length of the shortest path from Vertex xj and Vertex yj via Vertex K.

    Constraints

    • 3N105
    • 1ai,biN(1iN1)
    • 1ci109(1iN1)
    • The given graph is a tree.
    • 1Q105
    • 1KN
    • 1xj,yjN(1jQ)
    • xjyj(1jQ)
    • xjK,yjK(1jQ)

    Input

    Input is given from Standard Input in the following format:

    N  
    a1 b1 c1  
    :  
    aN1 bN1 cN1
    Q K
    x1 y1
    :  
    xQ yQ
    

    Output

    Print the responses to the queries in Q lines.
    In the j-th line j(1jQ), print the response to the j-th query.


    Sample Input 1

    Copy
    5
    1 2 1
    1 3 1
    2 4 1
    3 5 1
    3 1
    2 4
    2 3
    4 5
    

    Sample Output 1

    Copy
    3
    2
    4
    

    The shortest paths for the three queries are as follows:

    • Query 1: Vertex 2 → Vertex 1 → Vertex 2 → Vertex 4 : Length 1+1+1=3
    • Query 2: Vertex 2 → Vertex 1 → Vertex 3 : Length 1+1=2
    • Query 3: Vertex 4 → Vertex 2 → Vertex 1 → Vertex 3 → Vertex 5 : Length 1+1+1+1=4

    求x到k加y到k的最小距离,最短路问题。

     1 #include <bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 const int N = 1e5+10;
     5 const ll INF = 1LL<<60;
     6 struct Nod {
     7     ll to, cost;
     8 };
     9 vector<Nod> G[N];
    10 ll dist[N];
    11 typedef pair<ll, ll> P;
    12 void dij(ll x) {
    13     priority_queue<P, vector<P>, greater<P> > que;
    14     for(int i = 0; i < N; i ++) dist[i] = INF;
    15     dist[x] = 0;
    16     que.push(P(0, x));
    17     while(!que.empty()) {
    18         P p = que.top();
    19         que.pop();
    20         ll v = p.second;
    21         if(dist[v] < p.first) continue;
    22         for(ll i = 0; i < G[v].size(); i ++) {
    23             Nod e = G[v][i];
    24             if(dist[e.to] > dist[v] + e.cost) {
    25                 dist[e.to] = dist[v] + e.cost;
    26                 que.push(P(dist[e.to], e.to));
    27             }
    28         }
    29     }
    30 }
    31 int main() {
    32     int n, q, cnt = 0;
    33     scanf("%d", &n);
    34     for(int i = 0; i < n-1; i ++) {
    35         ll v, u, w;
    36         scanf("%lld %lld %lld", &v, &u, &w);
    37         G[v].push_back((Nod){u,w});
    38         G[u].push_back((Nod){v,w});
    39     }
    40      ll k;
    41      scanf("%d %lld", &q, &k);
    42      dij(k);
    43      while(q--) {
    44          ll x, y;
    45          scanf("%lld %lld", &x, &y);
    46          printf("%lld
    ",dist[x] + dist[y]);
    47      }
    48     return 0;
    49 }
  • 相关阅读:
    TCP通信 小例子
    Socket的简单使用
    Redis练习
    资料
    Redis封装帮助类
    使用Redis的基本操作
    Redis配置主从
    Redis基本设置
    clientHeight ,offsetHeight,style.height,scrollHeight的区别与联系
    服务器操作之如何绑定网站
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7368137.html
Copyright © 2020-2023  润新知