codeforces_Codeforces Round #541 (Div. 2)_abc
1 second
256 megabytes
standard input
standard output
In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w1w1 and a height of h1h1, while the second rectangle has a width of w2w2 and a height of h2h2, where w1≥w2w1≥w2. In this game, exactly one ship is used, made up of two rectangles. There are no other ships on the field.
The rectangles are placed on field in the following way:
- the second rectangle is on top the first rectangle;
- they are aligned to the left, i.e. their left sides are on the same line;
- the rectangles are adjacent to each other without a gap.
See the pictures in the notes: the first rectangle is colored red, the second rectangle is colored blue.
Formally, let's introduce a coordinate system. Then, the leftmost bottom cell of the first rectangle has coordinates (1,1)(1,1), the rightmost top cell of the first rectangle has coordinates (w1,h1)(w1,h1), the leftmost bottom cell of the second rectangle has coordinates (1,h1+1)(1,h1+1) and the rightmost top cell of the second rectangle has coordinates (w2,h1+h2)(w2,h1+h2).
After the ship is completely destroyed, all cells neighboring by side or a corner with the ship are marked. Of course, only cells, which don't belong to the ship are marked. On the pictures in the notes such cells are colored green.
Find out how many cells should be marked after the ship is destroyed. The field of the game is infinite in any direction.
Four lines contain integers w1,h1,w2w1,h1,w2 and h2h2 (1≤w1,h1,w2,h2≤1081≤w1,h1,w2,h2≤108, w1≥w2w1≥w2) — the width of the first rectangle, the height of the first rectangle, the width of the second rectangle and the height of the second rectangle. You can't rotate the rectangles.
Print exactly one integer — the number of cells, which should be marked after the ship is destroyed.
2 1 2 1
12
2 2 1 2
16
In the first example the field looks as follows (the first rectangle is red, the second rectangle is blue, green shows the marked squares):

In the second example the field looks as:

思路:有两个长方形,都是左对齐,一个摆放在另一个上面,求相邻的绿色格子有多少个。
要注意上下长方形的宽度不同的时候、拐角处的格子。
#include <iostream>
#include <cstdio> using namespace std; int main()
{
long long w1,h1,w2,h2;
while(~scanf("%I64d %I64d %I64d %I64d",&w1,&h1,&w2,&h2)){
if(w2==w1){
printf("%I64d\n",w1+w2++(h1+h2)*);
}else{
printf("%I64d\n",w1+w2++(h1+h2)*+(w1-w2));
} }
return ;
}
2 seconds
256 megabytes
standard input
standard output
You still have partial information about the score during the historic football match. You are given a set of pairs (ai,bi)(ai,bi), indicating that at some point during the match the score was "aiai: bibi". It is known that if the current score is «xx:yy», then after the goal it will change to "x+1x+1:yy" or "xx:y+1y+1". What is the largest number of times a draw could appear on the scoreboard?
The pairs "aiai:bibi" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.
The first line contains a single integer nn (1≤n≤100001≤n≤10000) — the number of known moments in the match.
Each of the next nn lines contains integers aiai and bibi (0≤ai,bi≤1090≤ai,bi≤109), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team).
All moments are given in chronological order, that is, sequences xixi and yjyj are non-decreasing. The last score denotes the final result of the match.
Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.
3
2 0
3 1
3 4
2
3
0 0
0 0
0 0
1
1
5 4
5
In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.
题意:给出几个比赛时的分数,求这场比赛中最多可以有多少个平局的状态。
可以挨着算,第一个状态肯定是0:0,然后算第一个比分跟0:0之间有多少个,再第二个跟第一个之间,依次类推。
要注意上一个的比分是平局的时候,就不再+1了,因为上一个的计算中已经算进去了。
#include <iostream>
#include <cstdio>
#include <cmath> using namespace std; int main()
{
int n;
int a,b;
int res=;
int la=,lb=;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d %d",&a,&b);
if(a==la&&b==lb&&i!=){
continue;
}
int tmp=min(a,b);
int tmp2=max(la,lb);
if(tmp2>tmp){
}else{
if(la!=lb){
res+=(tmp-tmp2+);
}else{
res+=(tmp-tmp2);
} }
la=a,lb=b;
}
printf("%d\n",res);
return ;
}
C. Birthday
1 second
256 megabytes
standard input
standard output
Cowboy Vlad has a birthday today! There are nn children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.
Formally, let's number children from 11 to nn in a circle order, that is, for every ii child with number ii will stand next to the child with number i+1i+1, also the child with number 11 stands next to the child with number nn. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.
Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.
The first line contains a single integer nn (2≤n≤1002≤n≤100) — the number of the children who came to the cowboy Vlad's birthday.
The second line contains integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) denoting heights of every child.
Print exactly nn integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.
If there are multiple possible answers, print any of them.
5
2 1 1 3 2
1 2 3 2 1
3
30 10 20
10 20 30
In the first example, the discomfort of the circle is equal to 11, since the corresponding absolute differences are 11, 11, 11 and 00. Note, that sequences [2,3,2,1,1][2,3,2,1,1] and [3,2,1,1,2][3,2,1,1,2] form the same circles and differ only by the selection of the starting point.
In the second example, the discomfort of the circle is equal to 2020, since the absolute difference of 1010 and 3030 is equal to 2020.
题意:一串数字,让他们围成圈,求一个“不舒服的值”最小的情况,这个不舒服的值是每个数字之间差的绝对值的最大值。
排序,然后正着取奇数位,倒着取偶数位。
#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std; int main()
{
int n;
int a[];
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
printf("%d",a[]);
if(n%==){
for(int i=;i<n-;i++,i++){
printf(" %d",a[i]);
}
for(int i=n-;i>=;i--,i--){
printf(" %d",a[i]);
}
}else{
for(int i=;i<n;i++,i++){
printf(" %d",a[i]);
}
for(int i=n-;i>=;i--,i--){
printf(" %d",a[i]);
}
}
printf("\n");
return ;
}
codeforces_Codeforces Round #541 (Div. 2)_abc的更多相关文章
- Codeforces Round #541 (Div. 2)
Codeforces Round #541 (Div. 2) http://codeforces.com/contest/1131 A #include<bits/stdc++.h> us ...
- Codeforces Round #541 (Div. 2)题解
不知道该更些什么 随便写点东西吧 https://codeforces.com/contest/1131 ABC 太热了不写了 D 把相等的用并查集缩在一起 如果$ x<y$则从$ x$往$y$ ...
- Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)
D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: = 的情况我们用并查集把他们扔到一个集合,然后根据 > ...
- Codeforces Round #541 (Div. 2) (A~F)
目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质
https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...
- Codeforces Round #541 (Div. 2) D 并查集 + 拓扑排序
https://codeforces.com/contest/1131/problem/D 题意 给你一个n*m二维偏序表,代表x[i]和y[j]的大小关系,根据表构造大小分别为n,m的x[],y[] ...
- Codeforces 1131 F. Asya And Kittens-双向链表(模拟或者STL list)+并查集(或者STL list的splice()函数)-对不起,我太菜了。。。 (Codeforces Round #541 (Div. 2))
F. Asya And Kittens time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 1131 C. Birthday-暴力 (Codeforces Round #541 (Div. 2))
C. Birthday time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
随机推荐
- 生成透视列之for xml path
临时表#t原始数据: 实现如下格式,即根据Province分组,把每个组对应的City列以某种格式展示: 实现方法: select t.Province,(select city+',' From # ...
- C#中上下文Context的理解
上下文指的是 进程间占有的资源空间. 当一个进程时间片到了或者资缺的时候就会让出cpu 当另一个进程开始始用CPU之前,系统要保存即将退出进程的执行状态,以便轮到时间片或有资源的时候现场恢复.这就所谓 ...
- VUE环境项目搭建以及简单的运行例子
1.打开cmd命令窗口,node-v和npm-v可以查看相应的安装版本信息. 2.使用一下命令全局安装vue-cli. 1)npm install -g vue-cli 2)如果使用淘宝镜像,则是 ...
- 高可用Redis(九):Redis Sentinel
1.主从复制高可用的问题 主从复制高可用的作用 1.为master提供备份,当master宕机时,slave有完整的备份数据 2.对master实现分流,实现读写分离 但是主从架构有一个问题 1.如果 ...
- js实现多个小球碰撞
实现思路:小球的移动,是通过改变小球的left和top值来改变,坐标分别为(x,y)当x/y值加到最大,即加到父级的宽度或者高度时,使x值或者y值减小,同理当x值或者y值减到最小时,同样的使x值或者y ...
- 如何在Django中配置MySQL数据库
直接上图 在项目中直接找到settings 文件 第一步 原始Django自带数据库 第二步将配置改成MySQL的数据 第三步 在__init__文件中告知Django使用MySQL数据 ...
- python3解决 json.dumps中文乱码
使用json.dumps()运行结果如下 role_name字段中文乱码了 只需要使用ensure_ascii=False 运行结果如下:
- vue 结合 FileReader() 实现上传图片预览功能
项目中 身份证上传需求: <div class="ID_pic_wrap"> <ul> <li> <img src="../.. ...
- JS截取页面,并保存到本地
想截取浏览器上内容,并做成图片保存到本地. 可以使用html2canvas.js进行操作. <!DOCTYPE html> <html lang="en"> ...
- dataGridView笔记
最近用dataGridView比较多,先把代码备份在这里,有时间系统总结一下 using FindId.DAL; using FindId.Model; using System; using Sys ...