2018国庆第四场个人赛

版权声明:转载时 别忘了注明出处 https://blog.csdn.net/ZCY19990813/article/details/82938304

前三个题超水 29分钟一遍AC  仔细看最后的题

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

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

Input

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

Output

Print 3

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

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

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

Input

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

Output

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

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 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
#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stack>
#include <deque>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
using namespace std;
typedef long long ll;
map<char,ll> M;
int main()
{
    ll n,i,a,b,c,x,y,z;
    cin>>n;
    a=1;
    b=1;
    x=n-a-b;
    if(x%3!=0)
        cout<<a<<" "<<b<<" "<<x<<endl;
    else
    if((x-1)%3!=0)
      cout<<a<<" "<<b+1<<" "<<x-1<<endl;
    else
        if((x-2)%3!=0)
          cout<<a+1<<" "<<b+1<<" "<<x-2<<endl;
}

 There are n points on the plane, (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 n(1≤n≤105).

Each of the next n lines contains two integers xi and yi (1≤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:

#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stack>
#include <deque>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
using namespace std;
typedef long long ll;
map<char,ll> M;
int main()
{
    ll i,j,n,a,b,maxx=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a>>b;
        if(a+b>=maxx)
            maxx=a+b;
    }
    cout<<maxx<<endl;
}

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.

#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stack>
#include <deque>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
using namespace std;
typedef long long ll;
map<char,ll> M;
int main()
{
    char s[6];
    int ans=0,a=0,b=0,c=0,d=0;
    cin>>s;
    a=s[0]-48;
    b=s[1]-48;
    c=s[3]-48;
    d=s[4]-48;
    while(1)
    {
        if(a==d&&b==c)
            break;
        d++;
        ans++;
        //cout<<"*"<<endl;
        if(d>=10)
        {
            d-=10;
            c+=1;
        }
        if(c*10+d>=60)
        {
            c=0;
            d=0;
            b+=1;
        }
        if(b>=10)
        {
            b-=10;
            a+=1;
        }
        else
        if(a*10+b>=24)
        {
            a=0;
            b=0;
        }
        //cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

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, 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

 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本书说时间适合在哪里  k是要求有几本书  q个问题 求问题中lr中有几个适合的时间

#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stack>
#include <deque>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
using namespace std;
typedef long long ll;
map<ll,ll> M;
ll vis[201000]={0};
int main()
{
    ll n,k,q,a,b,i;
    cin>>n>>k>>q;
    while(n--)
    {
        cin>>a>>b;
        M[a]++;
        M[b+1]--;//便于合起来
    }
    memset(vis,0,sizeof(vis));
    //VIS里面存的是满足条件的数
    ll num=0;
    for(i=0;i<200010;i++)
    {
        num+=M[i];
        if(num>=k)
            vis[i]=vis[i-1]+1;
        else
            vis[i]=vis[i-1];
    }
    while(q--)
    {
        cin>>a>>b;
        cout<<vis[b]-vis[a-1]<<endl;
    }
    return 0;
}

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.

题目大意:

每次操作可以选择一行或者一列进行整体+1的操作,问最少步数,使得一开始的全0矩阵变成输入进来的N*M的矩阵。

此代码并没有AC 忘大佬指正

整体思路是当行小于等于列时先遍历行,否则遍历列。

比如先遍历行:找到每一行的最小值,然后整行减去最小值,并记录是哪一行。然后找每一列的最小值,整列减去最小值,并记录是哪一列。

然后判断变化后的数组是不是全为0,是就输出刚刚记录的,不是就输出-1.

#include <iostream>
#include <algorithm>
#include<cstdio>
#include<stack>
#include <deque>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <deque>
#include <vector>
using namespace std;
typedef long long ll;
map<ll,ll> M;
struct A
{
    char s[4];
    int h;
}a[500];
int main()
{
    int g[110][110],gg[110][110],i,j,minn,n,m,c,e=0;
    cin>>n>>m;
    memset(gg,0,sizeof(gg));
    memset(g,0,sizeof(g));
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
          cin>>g[i][j];
    if(n<=m)//如果n>m先执行列
    {
        for(i=0;i<n;i++)
        {
            minn=5050;
            for(j=0;j<m;j++)
            {
                if(g[i][j]<=minn)
                    minn=g[i][j],c=i;
            }
            while(minn--)
            {
                for(j=0;j<m;j++)
                {
                    g[c][j]--;
                }
                a[e].s[0]='r';
                a[e].s[1]='o';
                a[e].s[2]='w';
                a[e].h=c+1;
                e++;
            }
        }
        for(j=0;j<m;j++)
        {
            minn=5050;
            for(i=0;i<n;i++)
            {
                if(g[i][j]<=minn)
                    minn=g[i][j],c=j;
            }
            while(minn--)
            {
                for(i=0;i<n;i++)
                    g[i][c]--;
                a[e].s[0]='c';
                a[e].s[1]='o';
                a[e].s[2]='l';
                a[e].h=c+1;
                e++;
            }
        }
        int ans=0;
        for(i=0;i<n;i++)
            for(j=0;j<m;j++)
              if(gg[i][j]==g[i][j])
                ans++;
        if(ans==n*m)
        {
            for(i=0;i<e;i++)
                cout<<a[i].s<<" "<<a[i].h<<endl;
        }
        else
            cout<<"-1"<<endl;
    }
    else
    {
        for(j=0;j<m;j++)
        {
            minn=5050;
            for(i=0;i<n;i++)
            {
                if(g[i][j]<=minn)
                    minn=g[i][j],c=j;
            }
            while(minn--)
            {
                for(i=0;i<n;i++)
                    g[i][c]--;
                a[e].s[0]='c';
                a[e].s[1]='o';
                a[e].s[2]='l';
                a[e].h=c+1;
                e++;
            }
        }
        for(i=0;i<n;i++)
        {
            minn=5050;
            for(j=0;j<m;j++)
            {
                if(g[i][j]<=minn)
                    minn=g[i][j],c=i;
            }
            while(minn--)
            {
                for(j=0;j<m;j++)
                {
                    g[c][j]--;
                }
                a[e].s[0]='r';
                a[e].s[1]='o';
                a[e].s[2]='w';
                a[e].h=c+1;
                e++;
            }
        }
        int ans=0;
        for(i=0;i<n;i++)
            for(j=0;j<m;j++)
              if(gg[i][j]==g[i][j])
                ans++;
        if(ans==n*m)
        {
            for(i=0;i<e;i++)
                cout<<a[i].s<<" "<<a[i].h<<endl;
        }
        else
            cout<<"-1"<<endl;
    }
    

猜你喜欢

转载自blog.csdn.net/ZCY19990813/article/details/82938304