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. 纯css3手机页面图标样式代码

    全部图标:http://hovertree.com/texiao/css/19/ 先看效果: 或者点这里:http://hovertree.com/texiao/css/19/hoverkico.ht ...

  2. 神奇的CSS3按钮特效

    点击这里查看效果 以下是源代码: <!doctype html> <html> <!-- author: @simurai --> <head> < ...

  3. Sublime Text使用配置介绍

    这篇文章很多内容都是来源自网络,发布这里当作自己留个底,以后不用到处去找 对于文本编辑器,我用过notepad2.notepad++.Editplus.UltraEdit.Vim.TextPad,都没 ...

  4. java web学习总结(十三) -------------------使用Session防止表单重复提交

    在平时开发中,如果网速比较慢的情况下,用户提交表单后,发现服务器半天都没有响应,那么用户可能会以为是自己没有提交表单,就会再点击提交按钮重复提交表单,我们在开发中必须防止表单重复提交. 一.表单重复提 ...

  5. springmvc的初始化参数绑定

    一.springmvc的初始化参数绑定 此种和我们之前说的类型转换非常相似,可以看作是一种类型转换 在初始化参数绑定时  重要的是参数类型 -------------------单日期的绑定 二. 配 ...

  6. Python学习基础知识概要

    1.输入输出 输出实例   1 2 print 'hello','world' hello world 输入实例   1 2 3 4 5 name = raw_input(); print " ...

  7. 分享20个最新的免费 UI 设计素材给设计师

    用户界面设计涉及到很多的创意,灵感以及需要与客户进行有效沟通的技能.良好的用户界面是一致的,可以使网站更容易理解和使用.UI设计的重点在于用户体验和互动,同时易于使用对于一个成功的移动应用程序来说非常 ...

  8. jquery实现多级下拉菜单

    支持多种浏览器,体验效果:http://keleyi.com/keleyi/phtml/jqmenu/4.htm 多级菜单,理论上支持无限多的层级,文件结构非常简单的,以下是完整代码: <!DO ...

  9. ASP.NET MVC 简介

    1. ASP.NET MVC 是什么? ASP.NET MVC是微软官方提供的以MVC模式为基础的ASP.NET Web应用程序(Web Application)框架,它由Castle的MonoRai ...

  10. 破壳漏洞利用payload—shellshock in the wild

    FireEye关于破壳漏洞(shellshock)在现实中的利用有一篇文章: shellshock in the wild 原文较长,进行了对CGI利用的详细分析,笔者比较感兴趣的是Shellshoc ...