A. Vasya the Hipster
题目分类:水题
题目描述:a and b (1 ≤ a, b ≤ 100)代表a双红袜子,b双蓝袜子。Vasya喜欢让两只脚穿的袜子颜色不一样,而且每天穿过的袜子会扔掉。问最多几天两只脚上袜子不一样,然后剩下的袜子还能穿几天。
解题思路:能红蓝配对的尽量配对,剩下的整除2。
AC代码:
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cctype>
#include<string>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
intmain(){
int a,b;
while(~scanf("%d%d",&a,&b)){
int c=min(a,b);
int d=a-c;
int ee=b-c;
int g=max(d,ee);
printf("%d %d\n",c,g/2);
}
return 0;
}
原题描述:
A.Vasya the Hipster
timelimit per test
1second
memorylimit per test
256megabytes
input
standardinput
output
standardoutput
One day Vasya the Hipster decided to counthow many socks he had. It turned out that he had a red socks and b blue socks.
According to the latest fashion, hipstersshould wear the socks of different colors: a red one on the left foot, a blueone on the right foot.
Every day Vasya puts on new socks in themorning and throws them away before going to bed as he doesn't want to washthem.
Vasya wonders, what is the maximum numberof 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 ofsocks or cannot make a single pair from the socks he's got.
Can you help him?
Input
The single line of the input contains twopositive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks thatVasya's got.
Output
Print two space-separated integers — themaximum number of days when Vasya can wear different socks and the number ofdays when he can wear the same socks until he either runs out of socks orcannot make a single pair from the socks he's got.
Keepin mind that at the end of the day Vasya throws away the socks that he's beenwearing on that day.
Sampletest(s)
Input
3 1
Output
1 1
Input
2 3
Output
2 0
Input
7 3
Output
3 2
Note
In thefirst sample Vasya can first put on one pair of different socks, after that hehas two red socks left to wear on the second day.
B. Luxurious Houses
题目分类:贪心策略
题目描述:一条直线上有n栋楼,每栋楼高度依次为hi(1<=i<=n)。问对于每栋楼来讲,至少增高多少米可以使它比它右边的所有楼都高。(这是n个独立的问题,只是问至少增高多少,实际上不增长)。
解题思路:从右到左扫描楼层高度,只记录i+1到n的最高楼层为max米,如果比第i栋楼高则答案是max-h[i]+1,否则是0。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
using namespace std;
const int N = 101010;
const int inf = 0x3f3f3f3f;
int a[N];
int ans[N];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int ma = -inf;
for(int i=n-1;i>=0;i--)
{
if(a[i]>ma) ans[i] = 0;
else ans[i] = ma+1-a[i];
ma = max(ma,a[i]);
//ans[i] = ma - a[i];
//if(ans[i]) ans[i]++;
}
for(int i=0;i<n;i++)
{
printf("%d%c",ans[i],i==n-1?'\n':' ');
}
}
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 architectwho built up the capital was very creative, so all the houses were built in onerow.
Let's enumerate all the houses from left toright, starting with one. A house is considered to be luxurious ifthe number of floors in it is strictly greater than in all the houses withlarger numbers. In other words, a house is luxurious if the number of floors init is strictly greater than in all the houses, which are located to the rightfrom it. In this task it is assumed that the heights of floors in the housesare 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 the i-th house to make it luxurious?" (forall i from 1 to n, inclusive). You need to help him copewith this task.
Note that all these questions areindependent from each other — the answer to the question for house i does not affect other answers (i.e.,the floors to the houses are not actually added).
Input
The first line of the input contains asingle number n (1 ≤ n ≤ 105) — the number of houses in the capital ofBerland.
The second line contains n space-separated positiveintegers hi (1 ≤ hi ≤ 109), where hi equals the number of floors inthe i-th house.
Output
Print n integers a1, a2, ..., an, where number ai is the number of floors that need tobe added to the house number i to make it luxurious. If the house isalready luxurious and nothing needs to be added to it, then ai 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
B. Pasha and String 解题报告
题目分类:贪心策略(或者优先队列)
题目描述:n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107),n种技能,初始值为a[i],有k个技能点,可以分别用到n种技能中。问如何加技能点使能力最强。能力值是所有技能点整除10后类加。
解题思路:将n种技能的初始值按对10取余排序,从余数大的开始加。先尽量加到每个数对10余0,k如果用完就中止,输出答案。否则将剩余的k以10为单位随意加任意技能点就行。O(nlog(n))。
解题思路2:动态加技能点,还是以对10取余为标准把所有技能放进优先队列,每次取出余数最大的加到余数为零,加到k剩余零为止即可。算法复杂度大概是O(k/10*log(n))。
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<stack>
#include<algorithm>
#include<map>
using namespace std;
const int N = 1e5+10;
structnode
{
int x,y;
} a[N];
boolcmp(node a,nodeb)
{
return a.y<b.y;
}
intmain()
{
int n,k,tot=0;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i].x);
a[i].y=10-a[i].x%10;
tot+=a[i].x/10;
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++)
if (k>=a[i].y)
{
k-=a[i].y;
tot++;
}
k/=10;
int an=min(n*10,k+tot);
printf("%d\n",an);
return 0;
}
原题描述:
C.Developing Skills
timelimit per test
1second
memorylimit per test
256megabytes
input
standardinput
output
standardoutput
Petya loves computer games. Finally a gamethat he's been waiting for so long came out!
The main character of this game has n different skills, each of which ischaracterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The totalrating of the character is calculated as the sum of the values of for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.
At the beginning of the game Petya got k improvement units as a bonus that he canuse to increase the skills of his character and his total rating. Oneimprovement unit can increase any skill of Petya's character by exactly one.For example, if a4 = 46, after using one imporvement unit to thisskill, 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 wayof using the improvement units so as to maximize the overall rating of thecharacter. It is not necessary to use all the improvement units.
Input
The first line of the input contains twopositive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the characterand the number of units of improvements at Petya's disposal.
The second line of the input contains asequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character.
Output
Thefirst line of the output should contain a single non-negative integer — themaximum total rating of the character that Petya can get using k or less improvement units.
Sampletest(s)
Input
2 4
7 9
Output
2
Input
3 8
17 15 19
Output
5
Input
2 2
99 100
Output
20
D. Three Logos
题目分类:暴力枚举
题目描述:分别给出三个矩形的长宽,问经过旋转后三个矩形能否拼成一个正方形。能就输出方案。
解题思路:按照三个矩形是否有一维全相等分为两大类,每一类按照三个矩形旋转与否和位置排列分为2^3*3种情况讨论即可。记得灵活调用函数使代码易读。
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<stack>
#include<algorithm>
#include<map>
using namespace std;
const int N = 101010;
const int inf = 0x3f3f3f3f;
structcom
{
int x,y;
}f[10],g[10];
boolflag;
voidwork(int i,intj,int k)
{
if(f[i].y == f[j].y+f[k].y && f[j].x == f[k].x && f[i].x + f[j].x == f[i].y)
{
printf("%d\n",f[i].y);
for(int l=0;l<f[i].y;l++)
{
for(int r=0;r<f[i].y;r++)
{
if(r<f[i].x)
printf("%c",'A'+i);
else
{
if(l<f[j].y) printf("%c",'A'+j);
else printf("%c",'A'+k);
}
}
printf("\n");
}
flag = 1;
}
}
voiddfs(int i,intj,int k)
{
if(flag) return;
work(i,j,k);
if(flag) return;
swap(f[i].x,f[i].y);
work(i,j,k);
if(flag) return;
swap(f[j].x,f[j].y);
work(i,j,k);
if(flag) return;
swap(f[k].x,f[k].y);
work(i,j,k);
if(flag) return;
swap(f[i].x,f[i].y);
work(i,j,k);
if(flag) return;
swap(f[j].x,f[j].y);
work(i,j,k);
if(flag) return;
swap(f[i].x,f[i].y);
work(i,j,k);
if(flag) return;
swap(f[i].x,f[i].y);
swap(f[j].x,f[j].y);
swap(f[k].x,f[k].y);
work(i,j,k);
}
voidwork1(int i,intj,int k)
{
if(f[i].y == f[j].y && f[j].y == f[k].y && f[i].x+f[j].x+f[k].x == f[i].y)
{
flag = 1;
printf("%d\n",f[i].y);
for(int l=0;l<f[i].y;l++)
{
for(int r=0;r<f[i].y;r++)
{
if(l<f[i].x) printf("%c",'A'+i);
else
if(l>=f[i].x+f[j].x) printf("%c",'A'+k);
else printf("%c",'A'+j);
}
printf("\n");
}
}
}
voidbfs(int i,intj,int k)
{
if(flag) return;
work1(i,j,k);
if(flag) return;
swap(f[i].x,f[i].y);
work1(i,j,k);
if(flag) return;
swap(f[j].x,f[j].y);
work1(i,j,k);
if(flag) return;
swap(f[k].x,f[k].y);
work1(i,j,k);
if(flag) return;
swap(f[i].x,f[i].y);
work1(i,j,k);
if(flag) return;
swap(f[j].x,f[j].y);
work1(i,j,k);
if(flag) return;
swap(f[i].x,f[i].y);
work1(i,j,k);
if(flag) return;
swap(f[i].x,f[i].y);
swap(f[j].x,f[j].y);
swap(f[k].x,f[k].y);
work1(i,j,k);
}
intmain()
{
for(int i=0;i<3;i++)
scanf("%d%d",&g[i].x,&g[i].y);
flag = 0;
for(int i=0;i<3;i++) f[i] = g[i];
dfs(0,1,2);
for(int i=0;i<3;i++) f[i] = g[i];
dfs(1,0,2);
for(int i=0;i<3;i++) f[i] = g[i];
dfs(2,0,1);
if(!flag)
{
for(int i=0;i<3;i++) f[i] = g[i];
bfs(0,1,2);
}
if(!flag) printf("-1\n");
return 0;
}
原题描述:
D.Three Logos
timelimit per test
1second
memorylimit per test
256megabytes
input
standardinput
output
standardoutput
Three companies decided to order abillboard with pictures of their logos. A billboard is a big squareboard. A logo of each company is a rectangle of a non-zero area.
Advertisers will put up the ad only if itis possible to place all three logos on the billboard so that they do notoverlap and the billboard has no empty space left. When you put a logo on thebillboard, you should rotate it so that the sides were parallel to the sides ofthe billboard.
Your task is to determine if it is possibleto put the logos of all the three companies on some square billboard withoutbreaking any of the described rules.
Input
The first line of the input contains sixpositive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logoof the i-th company respectively.
Output
If it is impossible to place all the threelogos on a square shield, print a single integer "-1" (withoutthe quotes).
If it is possible, print in the first linethe 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 shouldform solid rectangles, provided that:
· thesizes of the rectangle composed from letters "A" should beequal to the sizes of the logo of the first company,
· thesizes of the rectangle composed from letters "B" should beequal to the sizes of the logo of the second company,
· thesizes of the rectangle composed from letters "C" should beequal to the sizes of the logo of the third company,
Note that the logos of the companies can berotated for printing on the billboard. The billboard mustn't have any emptyspace. If a square billboard can be filled with the logos in multiple ways, youare allowed to print any of them.
Seethe samples to better understand the statement.
Sampletest(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
小结:本次codeforces侧重考察了贪心,枚举和函数调用等编程的基本功,十分适合初学者和进阶者练习。