LUXURY 7

A.Little Pony and Expected Maximum

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 454C

Description

Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.

The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the m-th face contains m dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice n times.

Input

A single line contains two integers m and n (1 ≤ m, n ≤ 105).

Output

Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn‘t exceed 10  - 4.

Sample Input

Input

6 1

Output

3.500000000000

Input

6 3

Output

4.958333333333

Input

2 2

Output

1.750000000000

Hint

Consider the third test example. If you‘ve made two tosses:

  1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
  2. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
  3. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
  4. You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.

The probability of each outcome is 0.25, that is expectation equals to:

You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value

:抛6面骰子3次,如果要计算最大值为3的情况:3^3 - (3-1)^3

注意到很容易就能让指数爆long long,所以变成(3/6)^3 - ((3-1)/6)^3 。利用排列组合原理。

B。

Pashmak and Graph

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 459E

Description

Pashmak‘s homework is a problem about graphs. Although he always tries to do his homework completely, he can‘t solve this problem. As you know, he‘s really weak at graph theory; so try to help him in solving the problem.

You are given a weighted directed graph with n vertices and m edges. You need to find a path (perhaps, non-simple) with maximum number of edges, such that the weights of the edges increase along the path. In other words, each edge of the path must have strictly greater weight than the previous edge in the path.

Help Pashmak, print the number of edges in the required path.

Input

The first line contains two integers nm(2 ≤ n ≤ 3·105; 1 ≤ m ≤ min(n·(n - 1), 3·105)). Then, m lines follows. The i-th line contains three space separated integers: uiviwi(1 ≤ ui, vi ≤ n; 1 ≤ wi ≤ 105) which indicates that there‘s a directed edge with weight wi from vertex ui to vertex vi.

It‘s guaranteed that the graph doesn‘t contain self-loops and multiple edges.

Output

Print a single integer — the answer to the problem.

Sample Input

Input

3 31 2 12 3 13 1 1

Output

1

Input

3 31 2 12 3 23 1 3

Output

3

Input

6 71 2 13 2 52 4 22 5 22 6 95 4 34 3 4

Output

6

Hint

In the first sample the maximum trail can be any of this trails: .

In the second sample the maximum trail is .

In the third sample the maximum trail is .

一到很水的dp,只要知道原理,学过背包的都能做出来。

C - Boredom

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 456C

Description

Alex doesn‘t like boredom. That‘s why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.

Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let‘s denote it ak) and delete it, at that all elements equal to ak + 1 and ak - 1 also must be deleted from the sequence. That step bringsak points to the player.

Alex is a perfectionist, so he decided to get as many points as possible. Help him.

Input

The first line contains integer n (1 ≤ n ≤ 105) that shows how many numbers are in Alex‘s sequence.

The second line contains n integers a1a2, ..., an (1 ≤ ai ≤ 105).

Output

Print a single integer — the maximum number of points that Alex can earn.

Sample Input

Input

21 2

Output

2

Input

31 2 3

Output

4

Input

91 2 1 3 2 2 2 2 3

Output

10

Hint

Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.

dp题,很水。

D - Pashmak and Parmida‘s problem

Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 459D

Description

Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he‘s not)! Parmida has prepared the following test problem for Pashmak.

There is a sequence a that consists of n integers a1, a2, ..., an. Let‘s denote f(l, r, x) the number of indices k such that: l ≤ k ≤ r andak = x. His task is to calculate the number of pairs of indicies i, j(1 ≤ i < j ≤ n) such that f(1, i, ai) > f(j, n, aj).

Help Pashmak with the test.

Input

The first line of the input contains an integer n(1 ≤ n ≤ 106). The second line contains n space-separated integers a1, a2, ..., an(1 ≤ ai ≤ 109).

Output

Print a single integer — the answer to the problem.

Sample Input

Input

71 2 1 1 2 2 1

Output

8

Input

31 1 1

Output

1

Input

51 2 3 4 5

Output

0

树状数组,F[i]表示 < i 的f(l,r,x)有多少个。

E - Present

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 460C

Description

Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions.

There are m days left to the birthday. The height of the i-th flower (assume that the flowers in the row are numbered from 1 to n from left to right) is equal to ai at the moment. At each of the remaining m days the beaver can take a special watering and water w contiguous flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?

Input

The first line contains space-separated integers nm and w(1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an(1 ≤ ai ≤ 109).

Output

Print a single integer — the maximum final height of the smallest flower.

Sample Input

Input

6 2 32 2 2 2 1 1

Output

2

Input

2 5 15 8

Output

9

Hint

In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It‘s impossible to get height 3 in this test.

二分,并用pre[l] += 1 , pre[l+w] -= 1 ,来维护区间的变化,使判断的过程用O(n)实现。

但用线段树的成段更新也能过。

时间: 2024-10-10 05:43:10

LUXURY 7的相关文章

A Diesel is a luxury watch brand that is known to all the classes

When worn with almost any type of clothes, these watches can help you attain the charm of a dictator. Consider a brand such as Diesel. A Diesel is a luxury watch brand that is known to all the classes in the society. Former Iraqi President Saddam Hus

LUXURY 8

A - Gargari and Bishops Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 463C Description Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prov

根据76大细分词性对单词进行归组(二)

词性的重要性不言而喻,尤其是对于自然语言处理来说,哪怕就是记单词,根据词性对单词进行归组也是非常有帮助的. superword是一个Java实现的英文单词分析软件,主要研究英语单词音近形似转化规律.前缀后缀规律.词之间的相似性规律等等. 各大词性及其包括的词: 32.N-COUNT-COLL(可数集合名词) (词数:50) 1 aristocracy army array audience band 2 cast chapter command commission committee 3 co

[POI2014]HOT-Hotels

https://www.luogu.org/problem/show?pid=3565 枚举中间点 枚举中间点的子树 枚举距离 如果只有3个子树,那么对答案的贡献为a*b*c 假设现在来了第4个子树,那么答案会增加 d*(a*b+a*c+b*c) 再来第5个,答案增加e*(a*b+a*c+a*d+b*c+b*d+c*d) 括号里的数好像有点儿规律 用c2维护来维护它 d*(a*b+a*c+b*c)变到 e*(a*b+a*c+a*d+b*c+b*d+c*d) 增加了 e*(a+b+c) 所以用再用

Linux Netcat command – The swiss army knife of net

Swiss Army Knife of networking netcat is a versatile tool that is able to read and write data across TCP and UDP network . Combined with other tools and redirection it can be used in number of ways in your scripts. You will be surprised to see what y

HDU 2451 Simple Addition Expression(组合数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2451 Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twilight. The yacht is ablaze with lights and there comes out laughers and singing from the hall where an

linux ncat命令

netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它.使用netcat命令所能完成的事情令人惊讶. netcat所做的就是在两台电脑之间建立链接并返回两个数据流,在这之后所能做的事就看你的想像力了.你能建立一个服务器,传输文件,与朋友聊天,传输流媒体或者用它作为其它协议的独立客户端. 下面是一些使用netcat的例子. [A(172.31.100.7) B(172.31.100.23)] Linux netcat

Spring各种依赖注入对比

转自:http://www.jb51.net/article/81741.htm(谢谢楼主分享) 注解注入顾名思义就是通过注解来实现注入,Spring和注入相关的常见注解有Autowired.Resource.Qualifier.Service.Controller.Repository.Component. Autowired是自动注入,自动从spring的上下文找到合适的bean来注入 Resource用来指定名称注入 Qualifier和Autowired配合使用,指定bean的名称 Se

工厂设计模式之:简单工厂、工厂方法、抽象工厂

简单工厂模式(Simple Factory):简单工厂模式又叫静态工厂模式,顾名思义,通过一个具体的工厂类,在该工厂类中定义返回值为不同实例对象的静态方法,来获得各种具体的实例对象. 工厂方法模式(Factory Method):建立一个抽象工厂,其不同的工厂实例用来创建不同的产品实例对象(单个产品),如果要增加新的产品,只需增加新的产品工厂即可.符合开闭原则. 抽象工厂模式(Abstract Factory):建立一个抽象工厂,用来实例化工厂子类,这些工厂子类用来生产对应的产品族(即一组对象实