zoukankan      html  css  js  c++  java
  • 国庆练习4

    Little C Loves 3 I CF 1047A

    Description

    Little C loves number «3» very much. He loves all things about it.

    Now he has a positive integer nn. He wants to split nn into 33 positive integers a,b,ca,b,c, such that a+b+c=na+b+c=n and none of the 33 integers is a multiple of 33. Help him to find a solution.

    Input

    A single line containing one integer nn (3n1093≤n≤109) — the integer Little C has.

    Output

    Print 33 positive integers a,b,ca,b,c in a single line, such that a+b+c=na+b+c=n and none of them is a multiple of 33.

    It can be proved that there is at least one solution. If there are multiple solutions, print any of them.

    Sample Input

    Input
    3
    Output
    1 1 1
    Input
    233
    Output
    77 77 79


    题目意思:给你一个数n,要求将n分成3分,并且每一份都不能被3整除。
    解题思路:直接构造就好了。目的就是为了防止出现划分出的数是3的倍数,我们就将n按照是不是3的倍数分为两类。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int main()
     6 {
     7     int n;
     8     int a,b,c;
     9     scanf("%d",&n);
    10     if(n%3==0)
    11     {
    12         a=1;
    13         b=1;
    14         c=n-2;
    15     }
    16     else if(n%3==1||n%3==2)
    17     {
    18         a=1;
    19         b=2;
    20         c=n-3;
    21     }
    22     printf("%d %d %d
    ",a,b,c);
    23     return 0;
    24 }

    Cover Points CF 1047B

    Description

    There are nn points on the plane, (x1,y1),(x2,y2),,(xn,yn)(x1,y1),(x2,y2),…,(xn,yn).

    You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle.

    Input

    First line contains one integer nn (1n1051≤n≤105).

    Each of the next nn lines contains two integers xixi and yiyi (1xi,yi1091≤xi,yi≤109).

    Output

    Print the minimum length of the shorter side of the triangle. It can be proved that it's always an integer.

    Sample Input

    Input
    3
    1 1
    1 2
    2 1
    Output
    3
    Input
    4
    1 1
    1 2
    2 1
    2 2
    Output
    4

    Hint

    Illustration for the first example: 

    Illustration for the second example: 



    题目意思:求一个能将所有点覆盖掉的最小等腰三角形的腰长。
    解题思路:很水,找一个坐标(x,y),x+y最大的那个点的x+y值即为能够覆盖的最小等腰三角形的腰长!可以通过平移得到。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int main()
     6 {
     7     int n,i,x,y,sum;
     8     int maxs=-9999;
     9     scanf("%d",&n);
    10     for(i=1; i<=n; i++)
    11     {
    12         scanf("%d%d",&x,&y);
    13         sum=x+y;
    14         if(sum>maxs)
    15         {
    16             maxs=sum;
    17         }
    18     }
    19     printf("%d
    ",maxs);
    20     return 0;
    21 }

    Karen and Morning CF 816A

    Description

    Karen is getting ready for a new school day!

    It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.

    What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?

    Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.

    
    

    Input

    The first and only line of input contains a single string in the format hh:mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59).

    
    

    Output

    Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.

    
    

    Sample Input

    Input
    05:39
    Output
    11
    Input
    13:31
    Output
    0
    Input
    23:59
    Output
    1
    
    

    Hint

    In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.

    In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.

    In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.


    题目意思:女主角要在回文时刻起床,给你一个时刻,问到距离下一个回文时刻,女主角还能睡多久。
    解题思路:开始我一直在找小时和分钟关于回文的对称关系,希望能找到规律,后来一直出错,因为会有小时进位问题,后来改成直接暴力模拟,AC。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 char s[10];
     6 int main()
     7 {
     8     int h,m,a,b;
     9     int ans;
    10     gets(s);
    11     h=s[1]-'0'+(s[0]-'0')*10;
    12     m=s[4]-'0'+(s[3]-'0')*10;
    13     ans=0;
    14     //printf("%d %d
    ",h,m);
    15     while(1)
    16     {
    17         if(m%10==h/10&&h%10==m/10)///该起床了
    18         {
    19             break;
    20         }
    21         m++;
    22         ans++;
    23         if(m==60)
    24         {
    25             m=0;
    26             h++;
    27         }
    28         if(h==24)
    29         {
    30             h=0;
    31         }
    32     }
    33     printf("%d
    ",ans);
    34     return 0;
    35 }


    Karen and Coffee CF 816B

    Description

    To stay woke and attentive(专注的) during classes, Karen needs some coffee!

    Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".

    She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between li and ri degrees, inclusive, to achieve the optimal taste.

    Karen thinks that a temperature is admissible if at least k recipes recommend it.

    Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?

    Input

    The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.

    The next n lines describe the recipes. Specifically, the i-th line among these contains two integers li and ri (1 ≤ li ≤ ri ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between li and ri degrees, inclusive.

    The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.

    Output

    For each question, output a single integer on a line by itself, the number of admissible(容许的) integer temperatures between a and b degrees, inclusive.

    Sample Input

    Input
    3 2 4
    91 94
    92 97
    97 99
    92 94
    93 97
    95 96
    90 100
    Output
    3
    3
    0
    4
    Input
    2 1 1
    1 1
    200000 200000
    90 100
    Output
    0

    Hint

    In the first test case, Karen knows 3 recipes.

    1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive.
    2. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive.
    3. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.

    A temperature is admissible if at least 2 recipes recommend it.

    She asks 4 questions.

    In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.

    In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.

    In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.

    In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.

    In the second test case, Karen knows 2 recipes.

    1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree.
    2. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.

    A temperature is admissible if at least 1 recipe recommends it.

    In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.

    题目意思:女主为了得到最好的泡咖啡的温度,看了n本书,n本书推荐了n种的适合范围,她想要查询q次,a~b温度范围内有多少个温度是可以允许泡咖啡的时间(这个时间要求至少有k本数推荐过)。

    解题思路:当时没有做到这一道题。。。。总的来说这一道题使用前缀和来做,这道题是不是有点像给气球刷颜色的那一类题。

    N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?
     
    当时数据在做这一类题的时候,限于数据量的因素,使用了树状数字或者线段树这样的数据结构,这里就可以不去使用了。
     
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #define maxs 200010
     5 using namespace std;
     6 int n,k,q;
     7 int a[maxs];
     8 int sum[maxs];
     9 int main()
    10 {
    11     int i,r,l;
    12     scanf("%d%d%d",&n,&k,&q);
    13     for(i=0;i<n;i++)
    14     {
    15       scanf("%d%d",&l,&r);
    16       a[l]++;
    17       a[r+1]--;
    18     }
    19     for(i=1;i<maxs;i++)
    20     {
    21         a[i]+=a[i-1];
    22         if(a[i]>=k)///满足至少有k本书推荐
    23         {
    24             sum[i]++;
    25         }
    26     }
    27     for(i=1;i<maxs;i++)
    28     {
    29         sum[i]+=sum[i-1];
    30     }
    31     for(i=0;i<q;i++)
    32     {
    33         scanf("%d%d",&l,&r);
    34         printf("%d
    ",sum[r]-sum[l-1]);
    35     }
    36     return 0;
    37 }

     Karen and Game CF 816C 

    On the way to school, Karen became fixated on the puzzle game on her phone!

    The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.

    One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.

    To win the level, after all the moves, the number in the cell at the i-th row and j-th column should be equal to gi, j.

    Karen is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!

    Input

    The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively.

    The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500).

    Output

    If there is an error and it is actually not possible to beat the level, output a single integer -1.

    Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level.

    The next k lines should each contain one of the following, describing the moves in the order they must be done:

    • rowx, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row".
    • colx, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column".

    If there are multiple optimal solutions, output any one of them.

    Sample Input

    Input
    3 5
    2 2 2 3 2
    0 0 0 1 0
    1 1 1 2 1
    Output
    4
    row 1
    row 1
    col 4
    row 3
    Input
    3 3
    0 0 0
    0 1 0
    0 0 0
    Output
    -1
    Input
    3 3
    1 1 1
    1 1 1
    1 1 1
    Output
    3
    row 1
    row 2
    row 3

    Hint

    In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level:

    In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.

    In the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level:

    Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.

    题目意思:给出一个n*m的矩阵,每次可以每一行都减1或者每一列都减1,问最少能通过多少次操作,使得矩阵每一个元素都变成0。

    解题思路:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int a[110][110];
     6 int minr[110];
     7 int minc[110];
     8 int n,m;
     9 int main()
    10 {
    11     int i,j,t,ans;
    12     scanf("%d%d",&n,&m);
    13     memset(minr,1,sizeof(minr));
    14     memset(minc,1,sizeof(minc));
    15     for(i=0; i<n; i++)
    16     {
    17         for(j=0; j<m; j++)
    18         {
    19             scanf("%d",&t);
    20             a[i][j]=t;
    21             if(minr[i]>t)///每一行中最小的那个数
    22             {
    23                 minr[i]=t;
    24             }
    25             if(minc[j]>t)///每一列中最小的那个数
    26             {
    27                 minc[j]=t;
    28             }
    29         }
    30     }
    31     ans=0;
    32     if(n<=m)///行优先
    33     {
    34         int rminr=99999999;
    35         for(i=0; i<n; i++)
    36         {
    37             ans+=minr[i];///每一行以其中的最小数开始消除
    38             if(rminr>minr[i])
    39             {
    40                 rminr=minr[i];
    41             }
    42         }
    43         for(i=0; i<m; i++)
    44         {
    45             ans+=(minc[i]-=rminr);///对行消除后,每一列的最小数会发生改变,要减去最小行数
    46         }
    47     }
    48     else///列优先
    49     {
    50         int cminc=99999999;
    51         for(i=0; i<m; i++)
    52         {
    53             ans+=minc[i];
    54             if(cminc>minc[i])
    55             {
    56                 cminc=minc[i];
    57             }
    58         }
    59         for(i=0; i<n; i++)
    60         {
    61             ans+=(minr[i]-=cminc);
    62         }
    63     }
    64     for(i=0;i<n;i++)
    65     {
    66         for(j=0;j<m;j++)
    67         {
    68             if(a[i][j]-minr[i]-minc[j])///不为0
    69             {
    70                 printf("-1
    ");
    71                 return 0;
    72             }
    73         }
    74     }
    75     printf("%d
    ",ans);
    76     for(i=0;i<n;i++)
    77     {
    78         while(minr[i]--)
    79         {
    80             printf("row %d
    ",i+1);
    81         }
    82     }
    83     for(i=0;i<m;i++)
    84     {
    85         while(minc[i]--)
    86         {
    87             printf("col %d
    ",i+1);
    88         }
    89     }
    90     return 0;
    91 }
  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    2万元小投资冷门暴利行业有哪些?投资什么利润大?
    街边小投资冷门暴利行业有哪些?做什么生意利润高?
    高利润赚钱行业有哪些?300的利润使人疯狂
    大学生兼职托管干什么?大学生兼职平台有哪些?
    大学生兼职可以做什么?具体有哪些兼职可做?
    大学生兼职创业怎么做?具体做什么好?
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/9746816.html
Copyright © 2011-2022 走看看