A. Sea Battle
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print exactly one integer — the number of cells, which should be marked after the ship is destroyed.

Examples
input

Copy
2 1 2 1
output

Copy
12
input

Copy
2 2 1 2
output

Copy
16
Note

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 ;
}
B. Draw!
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input

Copy
3
2 0
3 1
3 4
output

Copy
2
input

Copy
3
0 0
0 0
0 0
output

Copy
1
input

Copy
1
5 4
output

Copy
5
Note

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

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input

Copy
5
2 1 1 3 2
output

Copy
1 2 3 2 1
input

Copy
3
30 10 20
output

Copy
10 20 30
Note

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的更多相关文章

  1. Codeforces Round #541 (Div. 2)

    Codeforces Round #541 (Div. 2) http://codeforces.com/contest/1131 A #include<bits/stdc++.h> us ...

  2. Codeforces Round #541 (Div. 2)题解

    不知道该更些什么 随便写点东西吧 https://codeforces.com/contest/1131 ABC 太热了不写了 D 把相等的用并查集缩在一起 如果$ x<y$则从$ x$往$y$ ...

  3. Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)

    D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: =  的情况我们用并查集把他们扔到一个集合,然后根据 > ...

  4. Codeforces Round #541 (Div. 2) (A~F)

    目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...

  5. Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)

    https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...

  6. Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质

    https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...

  7. Codeforces Round #541 (Div. 2) D 并查集 + 拓扑排序

    https://codeforces.com/contest/1131/problem/D 题意 给你一个n*m二维偏序表,代表x[i]和y[j]的大小关系,根据表构造大小分别为n,m的x[],y[] ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. git知识总结-1.git基础之git分布式

    1.前言 我们在介绍git版本管理的时候,没有提到“服务器”的概念,所有的版本管理操作,都是在本地进行的.这就是git与其它版本管理工具(如CVS.SVN等)最本质的区别所在:分布式. 所谓的分布式, ...

  2. 使用scrapy爬虫,爬取今日头条首页推荐新闻(scrapy+selenium+PhantomJS)

    爬取今日头条https://www.toutiao.com/首页推荐的新闻,打开网址得到如下界面 查看源代码你会发现 全是js代码,说明今日头条的内容是通过js动态生成的. 用火狐浏览器F12查看得知 ...

  3. 解决 win10 新建文件夹重命名卡死的另一种方法

    遇到 win10 新建文件夹重命名卡死时 根据网上的各种方法都不起作用时可以试一下这个方法. 文件夹属性 --- 自定义 --- 你想要那种文件夹 优化此文件夹 --- 把 [视频] 改成 [常规项目 ...

  4. 一, Python 一次性多行打印多个变量

    >>> n = 123 >>> f = 456.789 >>> s1 = 'hello ,world' >>> s2 = 'he ...

  5. js原型链+继承 浅析

    名称:    prototype--原型对象    __proto__--属性 原型链与继承网上搜索定义,看起来挺绕的 .先说继承: 所有的对象实例都可以共享原型对象包含的属性和方法  例如一个实例A ...

  6. IntelliJ IDEA使用SVN检出项目到本地工作空间

  7. c博客作业--分支、顺序结构

    1.本章学习总结 1.1思维导图 1.2本章学习体会及代码量学习体会 1.2.1学习体会 对于本章学习我感觉对代码有了初步的了解,一些简单的题目可以熟练掌握,但现在解决一道题目花的时间过多,不易发现那 ...

  8. vue交互

    1)如果vue想做交互,本身的框架是不支持的,需要引入vue-resurce库交互方式:get.post.jsonp 1.get方式methods: {    get: function () { / ...

  9. Javal连接字符串为Json

    public static String concatJson(String[] keys,String[] values,String[] alreadyJsonKeys){ if(keys==nu ...

  10. HttpListener 实现web服务器

    一.使用方法 1. Start()方法 允许此实例接受传入的请求.即开始监听 2. Stop()方法 处理完所有当前排队的请求后关闭HttpListener对象 3. GetContext()方法  ...