codeforces#322 div2

A. Vasya the Hipster
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One day Vasya the Hipster decided to count how many socks he had. It turned out that he hada red socks and b blue socks.

According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.

Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.

Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.

Can you help him?

Input

The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got.

Output

Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.

Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.

Sample test(s)
Input
3 1
Output
1 1
Input
2 3
Output
2 0
Input
7 3
Output
3 2
Note

In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.

水题代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <map>
#include <stdlib.h>
#include <algorithm>

#define eps 1e-5
#define inf 0x3f3f3f3f
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b)  ((a)<(b)?(a):(b))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1 | 1
#define lc rt<<1
#define rc rt<<1 | 1
#define getx2(a)  ((a)*(a))
#define Pi acos(-1.0)

typedef long long LL;
using namespace std;
int main()
{
   int a,b;
   scanf("%d%d",&a,&b);
   printf("%d %d\n",min(a,b),(max(a,b)-min(a,b))/2);
    return 0;
}

B. Luxurious Houses
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.

Let's enumerate all the houses from left to right, starting with one. A house is considered to beluxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.

The new architect is interested in n questions,i-th of them is about the following: "how many floors should be added to thei-th house to make it luxurious?" (for alli from 1 to n, inclusive). You need to help him cope with this task.

Note that all these questions are independent from each other — the answer to the question for housei does not affect other answers (i.e., the floors to the houses are not actually added).

Input

The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of houses in the capital of Berland.

The second line contains n space-separated positive integershi (1 ≤ hi ≤ 109), wherehi equals the number of floors in thei-th house.

Output

Print n integers a1, a2, ..., an, where numberai is the number of floors that need to be added to the house numberi to make it luxurious. If the house is already luxurious and nothing needs to be added to it, thenai should be equal to zero.

All houses are numbered from left to right, starting from one.

Sample test(s)
Input
5
1 2 3 1 2
Output
3 2 0 2 0 
Input
4
3 2 1 4
Output
2 3 4 0 

水题:注意为负值时直接改成0

代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <map>
#include <stdlib.h>
#include <algorithm>

#define eps 1e-5
#define inf 0x3f3f3f3f
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b)  ((a)<(b)?(a):(b))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1 | 1
#define lc rt<<1
#define rc rt<<1 | 1
#define getx2(a)  ((a)*(a))
#define Pi acos(-1.0)
#define N 100010

typedef long long LL;
using namespace std;
int a[N];
int b[N];
int main()
{
    int n;
    scanf("%d",&n);
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    int max1=a[n-1];
    for(int i=n-2; i>=0; i--)
    {
        b[i]=max1-a[i]+1;
        if(b[i]<0)b[i]=0;//负值直接改成0
        if(max1<a[i])
        {
            max1=a[i];
        }
    }
    for(int i=0; i<n-1; i++)
        printf("%d ",b[i]);
    printf("%d\n",b[n-1]);
    return 0;
}

C. Developing Skills
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya loves computer games. Finally a game that he's been waiting for so long came out!

The main character of this game has n different skills, each of which is characterized by an integerai from 0 to 100. The higher the numberai is, the higher is thei-th skill of the character. The total rating of the character is calculated as the sum of the values ​​of for alli from 1 to n. The expressionx denotes the result of rounding the numberx down to the nearest integer.

At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.

Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.

Input

The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105,0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal.

The second line of the input contains a sequence of n integersai (0 ≤ ai ≤ 100), whereai characterizes the level of thei-th skill of the character.

Output

The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get usingk or less improvement units.

Sample test(s)
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
Note

In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10}rfloor +  lfloor frac{100}{10} rfloor = 10 + 10 =  20.

In the second test the optimal strategy for Petya is to improve the first skill to 20 (by spending 3 improvement units) and to improve the third skill to 20 (in this case by spending 1 improvement units). Thus, Petya is left with 4 improvement units and he will be able to increase the second skill to 19 (which does not change the overall rating, so Petya does not necessarily have to do it). Therefore, the highest possible total rating in this example is.

In the third test case the optimal strategy for Petya is to increase the first skill to 100 by spending 1 improvement unit. Thereafter, both skills of the character will be equal to 100, so Petya will not be able to spend the remaining improvement unit. So the answer is equal to .

题意:给定n个技能,每个技能的分数为a[i]/10;且a[i]不能超过100;可以花费k个技能增强点来增强技能k点,求最后技能的最大值;

代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <map>
#include <stdlib.h>
#include <algorithm>

#define eps 1e-5
#define inf 0x3f3f3f3f
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b)  ((a)<(b)?(a):(b))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1 | 1
#define lc rt<<1
#define rc rt<<1 | 1
#define getx2(a)  ((a)*(a))
#define Pi acos(-1.0)
#define N 100010

typedef long long LL;
using namespace std;

int a[N];
int b[N];
int cmp(const void *a,const void *b)
{
    return *(int *)a-*(int *)b;
}
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int ans=0;
    int min1=inf;
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        ans+=a[i]/10;
        b[i]=(10-a[i]%10)%10;///注意这里,b[i]的范围只能是0-9,所以要再对10取余
        if(min1>a[i]/10)min1=a[i]/10;
    }
    qsort(b,n,sizeof(b[0]),cmp);///差值最小排序(与整点的差值)
    int sum=0;
    for(int i=0; i<n; i++)
    {
        if(k>=b[i]&&b[i])///
        {
            ans++;
            k-=b[i];
            a[i]+=b[i];
        }
        sum+=(100-a[i]);
    }
    if(k>sum)
    {
        ans+=sum/10;
    }
    else
    {
        ans+=k/10;
    }
    printf("%d\n",ans);
    return 0;
}

D. Three Logos
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Three companies decided to order a billboard with pictures of their logos. A billboard is a bigsquare board. A logo of each company is a rectangle of a non-zero area.

Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard.

Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules.

Input

The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi andyi determine the length and width of the logo of thei-th company respectively.

Output

If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes).

If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that:

  • the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company,
  • the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company,
  • the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company,

Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them.

See the samples to better understand the statement.

Sample test(s)
Input
5 1 2 5 5 2
Output
5
AAAAA
BBBBB
BBBBB
CCCCC
CCCCC
Input
4 4 2 6 4 2
Output
6
BBBBBB
BBBBBB
AAAACC
AAAACC
AAAACC
AAAACC

题意:给出三个company的logo所占的矩形的长宽,问能否组成一个正方形,若可以,则输出边长,及任意一种拼凑方案,否则输出-1;

先看面积是不是平方数,如果不是平方数那么绝对不可能拼凑出正方形直接输出-1,;

若是平方数,则去找到一种平凑方案;


对于拼凑方案只有两种情况:

情况1:


情况2:


对于情况一直接输出就好了,对于情况二,循环找到所属的情况输出;

代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <map>
#include <stdlib.h>
#include <algorithm>

#define eps 1e-5
#define inf 0x3f3f3f3f
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b)  ((a)<(b)?(a):(b))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1 | 1
#define lc rt<<1
#define rc rt<<1 | 1
#define getx2(a)  ((a)*(a))
#define Pi acos(-1.0)

typedef long long LL;
using namespace std;
int main()
{
    int p[3][2];
    char c[3]= {'A','B','C'};
    scanf("%d%d%d%d%d%d",&p[0][0],&p[0][1],&p[1][0],&p[1][1],&p[2][0],&p[2][1]);
    if(p[0][0]<p[0][1])swap(p[0][0],p[0][1]);
    if(p[1][0]<p[1][1])swap(p[1][0],p[1][1]);
    if(p[2][0]<p[2][1])swap(p[2][0],p[2][1]);
    int sum=0;
    for(int i=0; i<3; i++)
    {
        sum+=p[i][0]*p[i][1];
    }
    int n=sqrt(sum);
    if(sum!=n*n)
    {
        printf("-1\n");
        return 0;
    }
    if(p[0][0]==p[1][0]&&p[1][0]==p[2][0]&&(p[0][0]==n&&p[0][1]+p[1][1]+p[2][1]==n))///情况1
    {
        printf("%d\n",n);
        for(int k=0; k<3; k++)
            for(int i=0; i<p[k][1]; i++)
            {
                for(int j=0; j<p[k][0]; j++)
                    printf("%c",c[k]);
                printf("\n");
            }
    }
    else
    {///枚举情况2
        for(int r=0; r<3; r++)
        {
            for(int cc=0; cc<3; cc++)
            {
                if(r!=cc)
                {
                    for(int i=0; i<2; i++)
                    {
                        for(int j=0; j<2; j++)
                        {
                            int kk;
                            if((r==0&&cc==1)||(r==1&&cc==0))kk=2;
                            if((r==1&&cc==2)||(r==2&&cc==1))kk=0;
                            if((r==2&&cc==0)||(r==0&&cc==2))kk=1;
                            if(p[r][i]+p[cc][j]==n&&p[r][(i+1)%2]+p[kk][1]==n&&p[kk][0]==n)//找到方案
                            {
                                printf("%d\n",n);///输出
                                for(int rr=0; rr<p[r][(i+1)%2]; rr++)
                                {
                                    for(int ccc=0; ccc<p[r][i]; ccc++)printf("%c",c[r]);
                                    for(int ccc=0; ccc<p[cc][j]; ccc++)printf("%c",c[cc]);
                                    printf("\n");
                                }
                                for(int rr=0; rr<p[kk][1]; rr++)
                                {
                                    for(int ccc=0; ccc<p[kk][0]; ccc++)
                                        printf("%c",c[kk]);
                                    printf("\n");
                                }
                                return 0;
                            }

                        }
                    }
                }
            }
        }//找不到方案输出-1
        printf("-1\n");
    }
    return 0;
}


     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值