cf之路,1,Codeforces Round #345 (Div. 2)

ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度。所以做了round#345连试试水的深浅。。。。。

      其实这个应该是昨天就写完的,不过没时间了,就留到了今天。。

A. Joysticks
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).

Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.

Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.

Input

The first line of the input contains two positive integers a1 and a2 (1 ≤ a1, a2 ≤ 100), the initial charge level of first and second joystick respectively.

Output

Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.

Examples
input
3 5
output
6
input
4 4
output
5
Note

In the first sample game lasts for 6 minute by using the following algorithm:

  • at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%;
  • continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%;
  • at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%;
  • continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%;
  • at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%;
  • at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.

After that the first joystick is completely discharged and the game is stopped.

题目大意:是给你两个(控制棒)电量a,b,并且只有一个充电器,每分钟的开始只能给一个充电;如果某分钟开始时,a没充电则电量减2,b充电则电量加1.如果a 或b等于0时则游戏结束(可以推出a=b=1时游戏也结束)。

现在让你求这个游戏能玩多久。

思路,对a,b比大小,使a>=b;每次给b充电,a不充,然后ab比大小使a>b,一直循环到游戏结束条件触发

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector> using namespace std; int main (void)
{
int a, b, t,time=;
cin >> a >> b;
if (a < b)
{
t = a;
a = b;
b = t;
}
while (a && b)
{
if (b == && a == )
{
break;
}
a -= ;
b++;
if (a < b)
{
t = a;
a = b;
b = t;
}
time++;
}
cout<<time<<endl;
return ;
}
 
 
B. Beautiful Paintings
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.

We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.

Input

The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting.

Output

Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.

Examples
input
5
20 30 10 50 40
output
4
input
4
200 100 100 200
output
2
Note

In the first sample, the optimal order is: 10, 20, 30, 40, 50.

In the second sample, the optimal order is: 100, 200, 100, 200.

题目大意是给你一个数列a[n],按某种方式排列后,a[i]<a[i+1]时,happy time+1,求happy time的最大值

思路:先对数组从小到大排序,然后遍历,遍历时如果数字相同的则只记录一次,把剩下的相同的数放数组头部(因为数组头已经不需要再用了),并记录压入数组头的数,不同的数则为此次的happytime数。然后重复上诉过程,直到压入数组的个数为0时结束,最后的happytime和即为答案;

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector> using namespace std;
int a[]; int main (void)
{
int n, temp, num = , tot=;
cin>>n;
for (int i = ; i < n; i++)
{
scanf("%d", &a[i]);
}
while (n)
{
sort(a, a + n);
num = ;
temp = a[];
for (int i = ; i < n; i++)
{
if (temp == a[i])
{
a[num++] = temp;
}
temp = a[i];
}
tot += n - num -;
n = num;
}
cout<<tot<<endl;
return ;
}
 
C. Watchmen
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There aren watchmen on a plane, the i-th watchman is located at point (xi, yi).

They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen i and j to be |xi - xj| + |yi - yj|. Daniel, as an ordinary person, calculates the distance using the formula .

The success of the operation relies on the number of pairs (i, j) (1 ≤ i < j ≤ n), such that the distance between watchman i and watchmen jcalculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.

Input

The first line of the input contains the single integer n (1 ≤ n ≤ 200 000) — the number of watchmen.

Each of the following n lines contains two integers xi and yi (|xi|, |yi| ≤ 109).

Some positions may coincide.

Output

Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.

Examples
input
3
1 1
7 5
1 5
output
2
input
6
0 0
0 1
0 2
-1 1
0 1
1 1
output
11
Note

In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and  for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.

题意:题目给你n个点的坐标,你要做的是求出其中符合规则(用 和|xi - xj| + |yi - yj|得到的答案相等)的点的对数,用数学化简一下,就能发现,只要两个点的x或y相等就可以

    所以先把坐标按x排序,求出每个x相同的点的个数(然后使用组合数公式C(N,2)),再对y排序,同样求出有多少对点相同,不过此时,会重复计算:如果一对点x相同y也相同,就会重复计算

  所以最后遍历求出重复计算的点的对数(同样使用组合数公式),想想为什么

  还有注意排序的方法

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector> using namespace std;
struct point
{
int x, y;
};
struct point a[]; bool cmp1(point a, point b)
{
if(a.x == b.x)
return a.y<b.y;
return a.x < b.x;
}
bool cmp2(point a, point b)
{
if(a.y==b.y)
return a.x<b.x;
return a.y<b.y;
}
int main (void)
{
long long n, num = , t, temp;
struct point p;
cin >> n;
for (int i = ; i < n; i++)
{
scanf("%d%d", &a[i].x, &a[i].y);
}
//因为当x或y相等时,两人算的结果会相同,所以先按x排序,求出x相等的点
//在用组合数公式c(x,2),然后按y排序,如果一对点的
//x和y都相等,就不计入个数
sort(a, a + n, cmp1);
t = a[].x;
temp = ;
for (int i = ; i < n; i++)
{
if (t == a[i].x)
{
temp++;
}
else
{
num += temp * (temp - ) / ;
temp = ;
t = a[i].x;
}
}
num += temp * (temp - ) / ;
sort(a, a + n, cmp2);
p = a[];
temp = ;
for (int i = ; i < n; i++)
if (p.y == a[i].y )
{
temp++;
p.x=a[i].x;
}
else
{
num += temp * (temp - ) / ;
temp = ;
p = a[i];
}
num += temp * (temp - ) / ;
temp = t=;
p=a[];
for (int i = ; i < n; i++)
if (p.y == a[i].y && p.x == a[i].x)
{
temp++;
}
else
{
t+=temp*(temp+)/;
temp=;
p = a[i];
}
t+=temp*(temp+)/;
cout << num-t<< endl;
return ;
}

还有几题没写,估计也不一定写的出来,毕竟渣渣

cf之路,1,Codeforces Round #345 (Div. 2)的更多相关文章

  1. 【cf比赛记录】Codeforces Round #601 (Div. 2)

    Codeforces Round #601 (Div. 2) ---- 比赛传送门 周二晚因为身体不适鸽了,补题补题 A // http://codeforces.com/contest/1255/p ...

  2. 【cf比赛记录】Codeforces Round #600 (Div. 2)

    Codeforces Round #600 (Div. 2) ---- 比赛传送门 昨晚成绩还好,AC A,B题,还能上分(到底有多菜) 补了C.D题,因为昨晚对C.D题已经有想法了,所以补起题来也快 ...

  3. 【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

    比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B ...

  4. 【cf比赛记录】Codeforces Round #605 (Div. 3)

    比赛传送门 Div3真的是暴力杯,比div2还暴力吧(这不是明摆的嘛),所以对我这种一根筋的挺麻烦的,比如A题就自己没转过头来浪费了很久,后来才醒悟过来了.然后这次竟然还上分了...... A题:爆搜 ...

  5. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  6. Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集

    题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...

  7. Codeforces Round #345 (Div. 2) A

    A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  8. Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集

    E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...

  9. Codeforces Round #345 (Div. 1) D. Zip-line 上升子序列 离线 离散化 线段树

    D. Zip-line 题目连接: http://www.codeforces.com/contest/650/problem/D Description Vasya has decided to b ...

随机推荐

  1. 谈一谈SQL Server中的执行计划缓存(下)

    简介 在上篇文章中我们谈到了查询优化器和执行计划缓存的关系,以及其二者之间的冲突.本篇文章中,我们会主要阐述执行计划缓存常见的问题以及一些解决办法. 将执行缓存考虑在内时的流程 上篇文章中提到了查询优 ...

  2. Gym 100703I---Endeavor for perfection(尺取)

    题目链接 http://codeforces.com/problemset/gymProblem/100703/I Description standard input/outputStatement ...

  3. ABP 初探 之 多语言

    最近几天空闲时间比较多,就研究Abp的多语言,Abp是基于接口的依赖注入,有很多思想与方法都很好,需自己深入体会与应用,转化成自己的思想应用于实践. 本篇介绍基于 开源Demo ModuleZeroS ...

  4. CSS Hack解决浏览器IE部分属性兼容性问题

    1.Css Hack 不同厂商的流览器或某浏览器的不同版本(如IE6-IE11,Firefox/Safari/Opera/Chrome等),对CSS的支持.解析不一样,导致在不同浏览器的环境中呈现出不 ...

  5. Android开发重点难点1:RelativeLayout(相对布局)详解

    前言 啦啦啦~博主又推出了一个新的系列啦~ 之前的Android开发系列主要以完成实验的过程为主,经常会综合许多知识来写,所以难免会有知识点的交杂,给人一种混乱的感觉. 所以博主推出“重点难点”系列, ...

  6. Linux-HA实战(1)— Heartbeat安装

    接触Heartbeat主要是因为之前项目中使用了TFS,最近想给nameserver做HA,因为TFS官方用的Heartbeat,所以刚好了解下,参考了网络上很多内容,这里简单记录下. 内容 环境和软 ...

  7. 自定义View字段表头

    适用场景: 三个列表进行Join,然后试图上显示ProjectedField,而ProjectedField不支持设置DisplayName.默认只能显示英文名. join caml如下: <V ...

  8. AFNetworking的理解

    AFNetworking的理解 使用方法 1. 新建的工程中导入AFNetworking3.0中的(AFNetworking 和UIKit+AFNetworking两个文件夹) 2. 在用到AFNet ...

  9. Android项目实战(二十七):数据交互(信息编辑)填写总结

    前言: 项目中必定用到的数据填写需求.比如修改用户名的文字编辑对话框,修改生日的日期选择对话框等等.现总结一下,方便以后使用. 注: 先写实现过程,想要学习的同学可以看看,不需要的同学可以直接拉到最下 ...

  10. Linux系统安装NoSQL(MongoDB和Redis)步骤及问题解决办法

    ➠更多技术干货请戳:听云博客 如下是我工作中的记录,介绍的是linux系统下NoSQL:MongoDB和Redis的安装过程和遇到的问题以及解决办法: 需要的朋友可以按照如下步骤进行安装,可以快速安装 ...