国庆个人赛——NO.4

1、

Codeforces——1047A

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 (3≤n≤1093≤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

扫描二维码关注公众号,回复: 3876869 查看本文章
3

Output

1 1 1

Input

233

Output

77 77 79

题意:

给定n,拆分成a、b、c三个数,要求a、b、c三个数都不是 3 的倍数

思路:

就拆分成至少含1的

如果求余 3 等于0的话,拆分成 2 2 n-4

如果求余 3 等于1的话,拆分成 1 1 n-2 (比3的倍数多 1,那么第三个数得和是2 ,不能是 3)

如果求余 3 等于2的话,拆分成 1 2 n-3

CODE:


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f

int main()
{
    LL n;
    scanf("%lld",&n);

    LL a,b,c;
    LL x;
    if(n==3)
        printf("1 1 1\n");
    else
    {
        if(n%3==1)
    {
        a=1;
        b=1;
        c=n-2;
    }
    else if(n%3==2)
    {
        a=1;
        b=2;
        c=n-3;
    }
    else
    {
        a=2;
        b=2;
        c=n-4;
    }
    printf("%lld %lld %lld",a,b,c);
    }

}

2、

Codeforces——1047B

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 (1≤n≤1051≤n≤105).

Each of the next nn lines contains two integers xixi and yiyi (1≤xi,yi≤1091≤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: 

题意:

平面上有n个点,用一个顶点在原点,两直角边分别在x轴和y轴的 等腰直角三角形 覆盖这些点,求将这些点全部覆盖的三角形的直角边最短是多长

思路: 

已知是等腰直角三角形,那么它的斜边肯定是在 y=-x+b 上,b就是与x轴y轴的交点,也就是我们要求的值

那么 b=x+y,直接去求 x+y的最大值即可

CODE:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f

int main()
{
    LL n,x,y;
    scanf("%lld",&n);
    LL maxx=-1;
    LL sum=0;
    while(n--)
    {
        sum=0;
        scanf("%lld %lld",&x,&y);
        sum=x+y;
        maxx=max(maxx,sum);
    }
    printf("%lld\n",maxx);

}

3、

Codeforces——816A

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, because 05: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.

题意:

给定一个时间,要求 Karen 醒来的时间点必须是回文,求醒来需要的最短时间

思路:

(1)、

有一种比较简单的,每次增加一秒判断是不是回文,当然需要判断 23:59+1 =00:00 的时间点

当分等于 60的时候,时 加1,分清零

输入也比较简单 直接输入 scanf(“%d:%d",&n,&m); 不用去输入字符串

CODE:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f

int check(int a,int b)
{
    int x;
    x=(a%10)*10+(a/10);
    if(x==b)
        return 1;
    return 0;
}
int main()
{
    int n,m;
    scanf("%d:%d",&n,&m);

    int ans=0;

    while(check(n,m)==0)
    {
        ans++;
        m++;
        if(m==60){
            n+=1;
            m=0;
        }
        if(n==24)
            n=0;
    }

    printf("%d\n",ans);
}

(2)、

我的方法就比较麻烦了,去分类一个一个判断的,po上我的代码提醒自己的代码有多low

需要注意几点:n:m

(1)、首先判断 n==m ?

(2)、当n等于23的时候

    m大于32的时候,输出 60-m(00:00 是一个最近的回文数),否则输出 32-m


(3)、相同的当n等于11的时候

    m大于11的时候,输出 60-m+21(12:21是一个最近的回文数),否则输出 11-m

(4)、05:51- 09:59中间没有回文数,最近的一个回文数是 10:01

    在05:00-05:50 之间的时候,直接用50-m

    同理:

    15:51-19:59中间没有回文数,最近的一个回文数是 20:02

    在15:00-15:50之间的时候,输出 51-m

(5)、其余情况

    当 m < n的回文数的时候,输出(n的回文数)-m

    否则,n的回文数加1 再减去 m

CODE:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f

int main()
{
    char s[10];
    scanf("%s",s);

    int x,y,xx;
    int a,b,ans,aa;

    if(s[0]==s[4]&&s[1]==s[3])
        printf("0\n");

    else
    {
        if(s[0]=='2'&&s[1]=='3')
        {
            x=(s[3]-'0')*10+(s[4]-'0');
            if(x<=32)
                printf("%d\n",32-x);
            else
                printf("%d\n",60-x);
            return 0;

        }

        if(s[0]=='1'&&s[1]=='1')
        {
            x=(s[3]-'0')*10+(s[4]-'0');
            if(x<=11)
                printf("%d\n",11-x);
            else
                printf("%d\n",60-x+21);
            return 0;
        }

        a=(s[0]-'0')*10+(s[1]-'0');
        aa=s[0]-'0'+(s[1]-'0')*10;

        if(a>=5&&a<=9)
        {
            b=(s[3]-'0')*10+(s[4]-'0');

            if(a==5&&aa>=b)
                printf("%d\n",aa-b);
            else
            {
                ans=(9-a)*60+(60-b)+1;
                printf("%d\n",ans);
            }
            return 0;
        }

        if(a>=15&&a<=19)
        {
            b=(s[3]-'0')*10+(s[4]-'0');
            if(a==15&&aa>=b)
                printf("%d\n",aa-b);
            else
            {
                ans=(19-a)*60+(60-b)+2;
                printf("%d\n",ans);
            }
        }
        else
        {
            x=(s[0]-'0')+(s[1]-'0')*10;
            y=(s[3]-'0')*10+(s[4]-'0');
            
            if(x>=y)
                printf("%d\n",x-y);
            else
            {
                xx=(s[0]-'0')+(s[1]-'0'+1)*10;
                xx+=60-y;
                printf("%d\n",xx);
            }
        }
    }

}

4、

Codeforces——816B

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, nk (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.

5、

Codeforces——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的矩阵,起初都是0,可以采取对某一行或某一列加 1操作,使得变成样例中的样子,求需要的最少步数以及输出对哪一行操作,有的情况是不符合题意的,需要输出 -1

猜你喜欢

转载自blog.csdn.net/JKdd123456/article/details/82938237