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. 基于.net mvc 的供应链管理系统(YB-SCM)开发随笔1-开篇

    作为开篇之作,先把这个项目的介绍和一些技术点给各位. 1.项目所用到的技术 (1)前台展示:ASP.NET MVC 3.0+Jquery+Sea+Bootstrap等 (2)开发环境:VS2012/V ...

  2. CSS基础之居中显示

    这些天忙完了一些项目后,终于有时间来总结一下了.自己就把做项目过程中的体会和理解到的一些东西和大家分享一下.有错请指正!! 在css中,元素居中显示,是基础也是一个小难点.我们经常不知为何总是不能把元 ...

  3. 纪念品分组 2007年NOIP全国联赛普及组

    题目描述 元旦快到了,校学生会让乐乐负责新年晚会的纪念品发放工作.为使得参加晚会的同学所获得的纪念品价值相对均衡,他要把购来的纪念品根据价格进行分组,但每组最多只能包括两件纪念品,并且每组纪念品的价格 ...

  4. jquery——左右按钮点击切换一组图片功能

    一.最终效果 二.功能分析 1.需求分析 点击左边pre按钮,显示前面三个图片,点击右边的next按钮,显示后面的一组(三个)图片.初始化只显示next按钮,到最后一组只显示pre按钮,中间过程两按钮 ...

  5. EC笔记:第二部分:12、复制对象时勿忘其每一个成分

    EC笔记:第二部分:12.复制对象时勿忘其每一个成分 1.场景 某些时候,我们不想使用编译器提供的默认拷贝函数(包括拷贝构造函数和赋值运算符),考虑以下类定义: 代码1: class Point{ p ...

  6. 动态加载js和css

    开发过程中经常需要动态加载js和css,今天特意总结了一下常用的方法. 1.动态加载js 方法一:动态加载js文件 // 动态加载js脚本文件 function loadScript(url) { v ...

  7. 【webapp的优化整理】要做移动前端优化的朋友进来看看吧

    单页or多页 本文仅代表个人观点,不足请见谅,欢迎赐教. webapp 小钗从事单页相关的开发一年有余,期间无比的推崇webapp的网站模式,也整理了很多移动开发的知识点,但是现在回过头来看,weba ...

  8. npm 入门

    要使用 npm 需要安装 node.js,因为 node.js 中会附带 npm 查看 node 的安装路径 which node 查看 npm 的安装路径 which npm npm 分为两种安装模 ...

  9. Linux0.11内核--加载可执行二进制文件之3.exec

    最后剩下最核心的函数do_execve了,由于这里为了简单起见我不分析shell命令的情况, /* * 'do_execve()'函数执行一个新程序. */ //// execve()系统中断调用函数 ...

  10. entity Framework codefirst Migrations

    一次数据迁移的记录 首先在vs工具里面使用打开程序包管理器控制台 在控制台上面选择程序集为数据访问层 注意配置生成app里面的连接字符串 在控制台输入 Enable-Migrations 会自动生成一 ...