zoukankan      html  css  js  c++  java
  • Codeforces Round #427 (Div. 2) (A B C)

    A. Key races

    Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds.

    If connection ping (delay) is t milliseconds, the competition passes for a participant as follows:

    1. Exactly after t milliseconds after the start of the competition the participant receives the text to be entered.
    2. Right after that he starts to type it.
    3. Exactly t milliseconds after he ends typing all the text, the site receives information about it.

    The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.

    Given the length of the text and the information about participants, determine the result of the game.

    Input

    The first line contains five integers s, v1, v2, t1, t2 (1 ≤ s, v1, v2, t1, t2 ≤ 1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.

    Output

    If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".

    Examples
    Input
    5 1 2 1 2
    Output
    First
    Input
    3 3 1 1 1
    Output
    Second
    Input
    4 5 3 1 5
    Output
    Friendship

    看谁用时少就行。
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main() {
     5     int s, v1, v2, t1, t2;
     6     cin>>s>>v1>>v2>>t1>>t2;
     7     int a = v1*s+2*t1, b = v2*s+2*t2;
     8     if(a < b)printf("First
    ");
     9     else if(a == b) printf("Friendship
    ");
    10     else printf("Second
    ");
    11     return 0;
    12 }

    B. The number on the board

    Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.

    You have to find the minimum number of digits in which these two numbers can differ.

    Input

    The first line contains integer k (1 ≤ k ≤ 109).

    The second line contains integer n (1 ≤ n < 10100000).

    There are no leading zeros in n. It's guaranteed that this situation is possible.

    Output

    Print the minimum number of digits in which the initial number and n can differ.

    Examples
    Input
    3
    11
    Output
    1
    Input
    3
    99
    Output
    0
    Note

    In the first example, the initial number could be 12.

    In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.

    从小到大排下序,每次改变最小的数就行。

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int MAX = 100010;
     4 char str[MAX];
     5 int main() {
     6     int k;
     7     cin >> k >> str;
     8     int sum = 0, len = strlen(str);
     9     for(int i = 0; i < len; i ++) {
    10         sum += str[i] - '0';
    11     }
    12     int ans = 0;
    13     sort(str,str+len);
    14     if(sum >= k) return 0*printf("0
    ");
    15     for(int i = 0; i < len; i ++) {
    16         if(str[i] != '9') {
    17             sum += '9' - str[i];
    18             ans++;
    19             if(sum >= k)return 0*printf("%d
    ",ans);
    20         }
    21     }
    22     return 0;
    23 }

    C. Star sky

    The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c).

    Over time the stars twinkle. At moment 0 the i-th star has brightness si. Let at moment t some star has brightness x. Then at moment (t + 1) this star will have brightness x + 1, if x + 1 ≤ c, and 0, otherwise.

    You want to look at the sky q times. In the i-th time you will look at the moment ti and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (x1i, y1i) and the upper right — (x2i, y2i). For each view, you want to know the total brightness of the stars lying in the viewed rectangle.

    A star lies in a rectangle if it lies on its border or lies strictly inside it.

    Input

    The first line contains three integers n, q, c (1 ≤ n, q ≤ 105, 1 ≤ c ≤ 10) — the number of the stars, the number of the views and the maximum brightness of the stars.

    The next n lines contain the stars description. The i-th from these lines contains three integers xi, yi, si (1 ≤ xi, yi ≤ 100, 0 ≤ si ≤ c ≤ 10) — the coordinates of i-th star and its initial brightness.

    The next q lines contain the views description. The i-th from these lines contains five integers ti, x1i, y1i, x2i, y2i (0 ≤ ti ≤ 109, 1 ≤ x1i < x2i ≤ 100, 1 ≤ y1i < y2i ≤ 100) — the moment of the i-th view and the coordinates of the viewed rectangle.

    Output

    For each view print the total brightness of the viewed stars.

    Examples
    Input
    2 3 3
    1 1 1
    3 2 0
    2 1 1 2 2
    0 2 1 4 5
    5 1 1 5 5
    Output
    3
    0
    3
    Input
    3 4 5
    1 1 2
    2 3 0
    3 3 1
    0 1 1 100 100
    1 2 2 4 4
    2 2 1 4 7
    1 50 50 51 51
    Output
    3
    3
    5
    0

    注意,在一个坐标上可以有两个或两个以上亮度相同的点。
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int a[110][110][110];
     4 int main() {
     5     int n,q,c;
     6     cin>>n>>q>>c;
     7     for(int i = 1; i <= n; i ++) {
     8         int x, y, s;
     9         cin>>x>>y>>s;
    10         for(int j = 0; j <= c; j ++) {
    11             a[j][x][y] += (s+j)%(c+1);
    12         }
    13     }
    14     for(int i = 1; i <= 100; i ++) {
    15         for(int j = 1; j <= 100; j ++) {
    16             for(int k = 0; k <= c; k ++) {
    17                 a[k][i][j] += a[k][i-1][j]+a[k][i][j-1]-a[k][i-1][j-1];
    18             }
    19         }
    20     }
    21     while(q--) {
    22         int x1,x2,y1,y2,t;
    23         cin>>t>>x1>>y1>>x2>>y2;
    24         t%=(c+1);
    25         printf("%d
    ",a[t][x2][y2]-a[t][x2][y1-1]-a[t][x1-1][y2]+a[t][x1-1][y1-1]);
    26     }
    27     return 0;
    28 }
  • 相关阅读:
    1、嵌入式Linux开发环境搭建
    JAVA_SE基础——1.JDK&JRE下载及安装
    数组
    Java方法的概述
    Java流程控制
    初识Java
    windows常用的快捷键和dos命令
    window10 Java JDK环境变量配置
    jQuery学习 (实现简单选项卡效果练习test)
    jQuery学习 (实现内联下拉菜单效果(一个小test)
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7267452.html
Copyright © 2011-2022 走看看