浙南联合训练赛20180414

这次题目的代码都不长,CF的一贯风格

A - Game

 CodeForces - 513A 

Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally.

Input

The first line contains four integers n1, n2, k1, k2. All numbers in the input are from 1 to 50.

This problem doesn't have subproblems. You will get 3 points for the correct submission.

Output

Output "First" if the first player wins and "Second" otherwise.

Examples

Input
2 2 1 2
Output
Second
Input
2 1 1 1
Output
First

Note

Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely.

A似曾相识,但是又不会做。First有n1个球,他每次可以移动k1个球;Second有n2个球,他每次可以移动k2个球

虽然是博弈,两个人都选择最优策略,但是其实两个人每次都是拿一个球的,所以就是比大小的题目

#include<bits/stdc++.h>
using namespace std;
int main()
{int n1,n2,k1,k2;cin>>n1>>n2>>k1>>k2;if(n1>n2)cout<<"First\n";elsecout<<"Second\n";return 0;
}

B - Water The Garden

 CodeForces - 920A 

It is winter now, and Max decided it's about time he watered the garden.

The garden can be represented as n consecutive garden beds, numbered from 1 to nkbeds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.

 The garden from test 1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.
 The garden from test 1after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed.

Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!

Input

The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 200).

Then t test cases follow. The first line of each test case contains two integers nand k (1 ≤ n ≤ 200, 1 ≤ k ≤ n) — the number of garden beds and water taps, respectively.

Next line contains k integers xi (1 ≤ xi ≤ n) — the location of i-th water tap. It is guaranteed that for each  condition xi - 1 < xi holds.

It is guaranteed that the sum of n over all test cases doesn't exceed 200.

Note that in hacks you have to set t = 1.

Output

For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.

Example

Input
3
5 1
3
3 3
1 2 3
4 1
1
Output
3
1
4

Note

The first example consists of 3 tests:

  1. There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
  2. There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
  3. There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.

这个是前一段时间的CF题目,花园要浇水,你有k个水井,1s可以浇当前这个点xi,也就是is你可以浇(xi-i,xi+i)

那我可以枚举每个点最小的浇灌值啊,所以最小的就是最大的了,和最短路那个很相似

#include<bits/stdc++.h>
using namespace std;
const int MAXN=205;
int x[MAXN];
int main()
{int T;scanf("%d",&T);while(T--){int n,k;scanf("%d%d",&n,&k);for(int i=1;i<=k;i++)scanf("%d",&x[i]);int res=0;for(int i=1;i<=n;i++){int mi=n;for(int j=1;j<=k;j++)mi=min(mi,abs(i-x[j]));res=max(res,mi);}printf("%d\n",res+1);}return 0;
}

C - Paper Work

 CodeForces - 250A 

Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is negative, then the company suffered losses on the i-th day.

Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the n days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.

It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (ai < 0), he loses his temper and his wrath is terrible.

Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.

Write a program that, given sequence ai, will print the minimum number of folders.

Input

The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai.

Output

Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1b2, ..., bk, where bj is the number of day reports in the j-th folder.

If there are multiple ways to sort the reports into k days, print any of them.

Examples

Input
11
1 2 3 -4 -5 -6 5 -5 -6 -7 6
Output
3
5 3 3
Input
5
0 -1 100 -1 0
Output
1
5

Note

Here goes a way to sort the reports from the first sample into three folders:

1 2 3 -4 -5 -6 5 -5 -6 -7 6

In the second sample you can put all five reports in one folder.

主要就是题意的理解了,超过三个负数是要划到下一个文件的,就是数够两个负数

一个负数要输出,没有也是坑点,最后一段也会被处理不好

#include <bits/stdc++.h>
using namespace std;
int a[105]={0};
int main()
{int n,t=0;cin>>n;for(int i=0,x;i<n;i++){cin>>x;if(x<0) a[i]=++t;}if(!t) t++;cout<<(t+1)/2<<endl;int x=0;for(int i=0;i<n;i++){if(a[i]%2==1&&a[i]!=1){if(x==0) cout<<i-x,x=i;else cout<<' '<<i-x,x=i;}}if(x) cout<<' ';cout<<n-x;
}

D - Anatoly and Cockroaches

 CodeForces - 719B 

Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.

Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.

Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.

The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.

Output

Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.

Examples

Input
5
rbbrr
Output
1
Input
5
bbbbb
Output
2
Input
3
rbr
Output
0

Note

In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1turn to do this.

In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.

In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.

这个序列要换为rb交替的,也就是可以r开头,也可以b开头

你可以交换任意两个,你也可以直接替换,所以就是找不对的r和b啊

交换任意两个rb之后替换,其实就是找最多不对的r和b

#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main()
{cin>>n;cin>>s;int r=0,b=0;for(int i=0;s[i];i++){char c;if(i%2)c='r';else c='b';if(s[i]!=c&&c=='r')r++;if(s[i]!=c&&c=='b')b++;}int ans=max(r,b);r=0,b=0;for(int i=0;s[i];i++){char c;if(i%2)c='b';else c='r';if(s[i]!=c&&c=='r')r++;if(s[i]!=c&&c=='b')b++;}cout<<min(max(r,b),ans);return 0;
}

E - Report

 CodeForces - 631C 

Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands of m managers. Each of them may reorder the elements in some order. Namely, the i-th manager either sorts first ri numbers in non-descending or non-ascending order and then passes the report to the manager i + 1, or directly to Blake (if this manager has number i = m).

Employees of the "Blake Technologies" are preparing the report right now. You know the initial sequence ai of length n and the description of each manager, that is value ri and his favourite order. You are asked to speed up the process and determine how the final report will look like.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of commodities in the report and the number of managers, respectively.

The second line contains n integers ai (|ai| ≤ 109) — the initial report before it gets to the first manager.

Then follow m lines with the descriptions of the operations managers are going to perform. The i-th of these lines contains two integers ti and ri (1 ≤ ri ≤ n), meaning that the i-th manager sorts the first ri numbers either in the non-descending (if ti = 1) or non-ascending (if ti = 2) order.

Output

Print n integers — the final report, which will be passed to Blake by manager number m.

Examples

Input
3 1
1 2 3
2 2
Output
2 1 3 
Input
4 2
1 2 4 3
2 3
1 2
Output
2 4 1 3 

Note

In the first sample, the initial report looked like: 1 2 3. After the first manager the first two numbers were transposed: 2 1 3. The report got to Blake in this form.

In the second sample the original report was like this: 1 2 4 3. After the first manager the report changed to: 4 2 1 3. After the second manager the report changed to: 2 4 1 3. This report was handed over to Blake.

历史总是惊人的相似,我们就是喜欢读错题。

1和2对应的是两种操作,把前b个换为不增或不降,直接写当然是不行的啊,但是每次都是前b个啊,所以你有些操作就变得无效了

我最后会确定它在哪个位置的,所以就是用单调栈去压缩一下

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],t[N],r[N],st[N];
int main()
{int n,m,s=0;cin>>n>>m;for(int i=0; i<n; i++)cin>>a[i];for(int i=0,a,b; i<m; i++){cin>>a>>b;while(s>0&&b>r[s-1])s--;t[s]=a,r[s]=b,s++;}r[s]=0,s++;for(int i=0; i<r[0]; i++)st[i]=a[i];sort(st,st+r[0]);int tl=0,tr=r[0]-1;for(int i=1; i<s; ++i)for(int j=r[i-1]; j>r[i]; --j)a[j-1]=(t[i-1]==1)?st[tr--]:st[tl++];for(int i=0; i<n; i++)cout<<a[i]<<" ";return 0;
}

 

F - Winnie-the-Pooh and honey

 CodeForces - 120C 

As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are n jars of honey lined up in front of Winnie-the-Pooh, jar number i contains ai kilos of honey. Winnie-the-Pooh eats the honey like that: each time he chooses a jar containing most honey. If the jar has less that k kilos of honey or if Winnie-the-Pooh has already eaten from it three times, he gives the jar to Piglet. Otherwise he eats exactly k kilos of honey from the jar and puts it back. Winnie does so until he gives all jars to the Piglet. Count how much honey Piglet will overall get after Winnie satisfies his hunger.

Input

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100). The second line contains n integers a1a2, ..., an, separated by spaces (1 ≤ ai ≤ 100).

Output

Print a single number — how many kilos of honey gets Piglet.

Examples

Input
3 3
15 8 10
Output
9

这个题我们理解错了啊,three times是三倍,不是三次,但是凑出来了答案
所以就是看它一倍两倍三倍,减一下就好了
#include<bits/stdc++.h>
using namespace std;
int main()
{freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);int n,k,x,a[105];cin>>n>>k;for(int i=0;i<n;i++)cin>>a[i];for(int i=0;i<n;i++){if(a[i]>=3*k)a[i]-=3*k;else if(a[i]>=2*k)a[i]-=2*k;else if(a[i]>=k)a[i]-=k;}int maxx=0;for(int i=0;i<n;i++)maxx+=a[i];cout<<maxx;return 0;
}

G - Alarm Clock

 CodeForces - 898D 

Every evening Vitalya sets n alarm clocks to wake up tomorrow. Every alarm clock rings during exactly one minute and is characterized by one integer ai — number of minute after midnight in which it rings. Every alarm clock begins ringing at the beginning of the minute and rings during whole minute.

Vitalya will definitely wake up if during some m consecutive minutes at least kalarm clocks will begin ringing. Pay attention that Vitalya considers only alarm clocks which begin ringing during given period of time. He doesn't consider alarm clocks which started ringing before given period of time and continues ringing during given period of time.

Vitalya is so tired that he wants to sleep all day long and not to wake up. Find out minimal number of alarm clocks Vitalya should turn off to sleep all next day. Now all alarm clocks are turned on.

Input

First line contains three integers nm and k (1 ≤ k ≤ n ≤ 2·1051 ≤ m ≤ 106) — number of alarm clocks, and conditions of Vitalya's waking up.

Second line contains sequence of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 106) in which ai equals minute on which i-th alarm clock will ring. Numbers are given in arbitrary order. Vitalya lives in a Berland in which day lasts for 106 minutes.

Output

Output minimal number of alarm clocks that Vitalya should turn off to sleep all next day long.

Examples

Input
3 3 2
3 5 1
Output
1
Input
5 10 3
12 8 18 25 1
Output
0
Input
7 7 2
7 3 4 1 6 5 2
Output
6
Input
2 2 2
1 3
Output
0

Note

In first example Vitalya should turn off first alarm clock which rings at minute 3.

In second example Vitalya shouldn't turn off any alarm clock because there are no interval of 10 consequence minutes in which 3 alarm clocks will ring.

In third example Vitalya should turn off any 6 alarm clocks.

这个题目是贪心,主要是知道题目意思,m个闹钟会在他的时间点ai响1min

你要让连续的m分钟闹钟个数小于k个,那就是查m个区段的闹钟数量,还有取消这个闹钟的情况

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int a[N];
int main()
{int n,m,k;cin>>n>>m>>k;for(int i=0,x;i<n;i++)cin>>x,a[x]=1;int ans=0,cnt=0;for(int i=1;i<N;i++){if(a[i])cnt++;if(i-m>0&&a[i-m])cnt--;//cout<<cnt;if(cnt>=k){ans++;cnt--;a[i]=0;}}cout<<ans;return 0;
}

 

H - Indian Summer

 CodeForces - 44A 

Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.

Output

Output the single number — the number of Alyona's leaves.

Examples

Input
5
birch yellow
maple red
birch yellow
maple yellow
maple green
Output
4
Input
3
oak yellow
oak yellow
oak yellow
Output
1

就是看下这个集合的元素个数

#include<bits/stdc++.h>
using namespace std;int main()
{int n;string s;map<string,int> ma;cin>>n;cin.get();for(int i=0;i<n;i++){getline(cin,s);ma[s]=1;}cout<<ma.size()<<endl;return 0;
}

I - Terse princess

 CodeForces - 148C 

«Next please», — the princess called and cast an estimating glance at the next groom.

The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing.

The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1.

Input

The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces.

Output

Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1.

Examples

Input
10 2 3
Output
5 1 3 6 16 35 46 4 200 99
Input
5 0 0
Output
10 10 6 6 5

Note

Let's have a closer look at the answer for the first sample test.

  • The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.
  • The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.

这个题目就是典型的构造题目

如果你是当前最大的就是Oh,如果你不仅最大了而且比前面总和还大就是Wow

有a次Oh,b次Wow

所以我就想分开构造,但是这个Wow很快就超了,所以现在先构造Wow,这个大佬想到了等比数列,1<<31-1是32967,所以还是够用的

所以主要是怎么判断-1,不可能Oh n-1次的,因为这是Wow(但是有0)

#include<bits/stdc++.h>
using namespace std;
int main()
{int n,a,b,sum=1;scanf("%d%d%d",&n,&a,&b);if(a==n-1&&n!=1){cout<<"-1";return 0;}cout<<"1";for(int i=0;i<b;i++)cout<<" "<<sum*2,sum=sum*2;for(int i=0;i<n-a-b-1;i++)cout<<" 1";for(int i=0;i<a;i++)cout<<" "<<sum+1,sum++;return 0;
}

J - Strip

 CodeForces - 487B 

 

Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.

Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy:

  • Each piece should contain at least l numbers.
  • The difference between the maximal and the minimal number on the piece should be at most s.

Please help Alexandra to find the minimal number of pieces meeting the condition above.

Input

The first line contains three space-separated integers n, s, l (1 ≤ n ≤ 105, 0 ≤ s ≤ 109, 1 ≤ l ≤ 105).

The second line contains n integers ai separated by spaces ( - 109 ≤ ai ≤ 109).

Output

Output the minimal number of strip pieces.

If there are no ways to split the strip, output -1.

Examples

Input
7 2 2
1 3 1 2 4 1 2
Output
3
Input
7 2 2
1 100 1 100 1 100 1
Output
-1

Note

For the first sample, we can split the strip into 3 pieces: [1, 3, 1], [2, 4], [1, 2].

For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists.

什么区间最大最小都是可以解决的,但是永远解决不掉的就是你要确定这个区间的端点,即使我知道这个区间要有的最大值和最小值了,但是我是无法得知现在在前一个区间,还是下一个区间

网上看到了别人的贪心代码,骚啊

就是你可以去决定这个能不能放进前一个区间的问题啊,太厉害了,不过这样的话我数组要开两倍了

被这个数据卡RE

忽悠你们学一波RMQ算法

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,INF=0x3f3f3f3f;
int dmi[N][22],dma[N][22],f[N],dp[N];
int n,s,l;
void RMQ_init()
{for(int j=1; (1<<j)<=n; j++)for(int i=1; i+j-1<=n; i++)dmi[i][j]=min(dmi[i][j-1],dmi[i+(1<<(j-1))][j-1]),dma[i][j]=max(dma[i][j-1],dma[i+(1<<(j-1))][j-1]);
}
int RMQ(int l,int r)
{int k=f[r-l+1];return max(dma[l][k],dma[r-(1<<k)+1][k])-min(dmi[l][k],dmi[r-(1<<k)+1][k]);
}
int main()
{f[0]=-1;scanf("%d%d%d",&n,&s,&l);for(int i=1,x; i<=n; i++)scanf("%d",&x),dmi[i][0]=dma[i][0]=x,f[i]=((i&(i-1))==0)?f[i-1]+1:f[i-1];RMQ_init();fill(dp+1,dp+n+1,INF);int pre=0;for(int i=1; i<=n; i++){while(i-pre>=l&&RMQ(pre+1,i)>s||dp[pre]==INF)pre++;if(i-pre>=l)dp[i]=min(dp[pre]+1,dp[i]);}cout<<(dp[n]==INF?-1:dp[n]);return 0;
}

K - Basketball Team

 CodeForces - 107B 

As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).

A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si — how many students who play basketball belong to this department.

Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department.

Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other.

Input

The first line contains three integers nm and h (1 ≤ n ≤ 100, 1 ≤ m ≤ 1000, 1 ≤ h ≤ m) — the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly.

The second line contains a single-space-separated list of m integers si (1 ≤ si ≤ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa.

Output

Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6.

Examples

Input
3 2 1
2 1
Output
1
Input
3 2 1
1 1
Output
-1
Input
3 2 1
2 2
Output
0.666667

Note

In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department.

In the second example, there are not enough players.

In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team.

这个其实就是个简单的组合数,因为和其他集合没有关系,你只用知道总数就好了

从不可能入手C(n-1, sum-1-a[h]) / C(n-1, sum-1)

#include<bits/stdc++.h>
using namespace std;
int a[1005];
int main()
{int n,m,h,sum=0;cin>>n>>m>>h;for(int i=1;i<=m;i++)cin>>a[i],sum+=a[i];if(sum<n){cout<<"-1";}else{double ans=1;for(int i=1;i<=n-1;i++)ans*=(sum*1.0-a[h]-i+1)/(sum-i);printf("%.12f\n",1-ans);}return 0;
}

L - Number of Parallelograms

 CodeForces - 660D

You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points.

Input

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

Each of the next n lines contains two integers (xi, yi) (0 ≤ xi, yi ≤ 109) — the coordinates of the i-th point.

Output

Print the only integer c — the number of parallelograms with the vertices at the given points.

Example

Input
4
0 1
1 0
1 1
2 0
Output
1

给你n个点,这些点任意三点不共线,也就是平行了,只要长度相等就行了

所以直接用中点这定理,两条线段的中点一样,就是一条直线

不知道怎么回事,没用成pair,直接hash一下吧,反正数也不大

#include<bits/stdc++.h>
using namespace std;
#define pair<double,double> pdd
const int N=2005,INF=0x3f3f3f3f;
map<long long,int>M;
struct p
{int x,y;
}d[N];
int main()
{int n;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d%d",&d[i].x,&d[i].y);for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)M[(d[i].x+d[j].x)*1LL*(2e9+5)+d[i].y+d[j].y]++;int ans=0;for(auto X:M){int x=X.second;ans+=x*(x-1)/2;}cout<<ans;return 0;
}

卡时间的代码

#include<bits/stdc++.h>
using namespace std;
#define pair<double,double> pdd
const int N=2005,INF=0x3f3f3f3f;
unordered_map<long long,int>M;
struct p
{int x,y;
}d[N];
int main()
{int n;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d%d",&d[i].x,&d[i].y);for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)M[(d[i].x+d[j].x)*1LL*(2e9+5)+d[i].y+d[j].y]++;int ans=0;for(auto X:M){int x=X.second;ans+=x*(x-1)/2;}cout<<ans;return 0;
}

 

转载于:https://www.cnblogs.com/BobHuang/p/8834664.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/254889.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

原生JS实现苹果菜单

今天分享下用原生JS实现苹果菜单效果&#xff0c;这个效果的重点有以下几点 图标中心点到鼠标的距离的算法 利用比例计算图标的宽度 代码地址&#xff1a;https://github.com/peng666/blogs/blob/gh-pages/menus/index.html 在线测试地址&#xff1a;http://peng666.github.io/…

Gym 100090D Insomnia

从 n 变到 1&#xff0c;有多少种方案&#xff1f; 打表记忆化。 1 #include <bits/stdc.h>2 3 using namespace std;4 5 int n;6 int dp[1000005];7 int dfs(int n) {8 if(n1)9 return 1; 10 if(dp[n]>0) 11 return dp[n]; 12 int cnt0;…

halcon rectangle1_domain缩减图像域为矩形

目录rectangle1_domain&#xff08;算子&#xff09;描述参数rectangle1_domain&#xff08;算子&#xff09; rectangle1_domain - 将图像的域缩小为矩形。 rectangle1_domain&#xff08;Image&#xff1a;ImageReduced&#xff1a;Row1&#xff0c;Column1&#xff0c;Row…

PC+运动控制卡的控制方案

PC运动控制卡的控制方案&#xff1a; 采用PC&#xff0b;运动控制卡作为上位控制可充分利用计算机资源&#xff0c;用于运动过程、运动轨迹都比较复杂&#xff0c;且柔性比较强的机器和设备。从用户使用的角度来看&#xff0c;基于PC机的运动控制卡主要是硬件接口&#xff08;输…

IP/TCP/UDP/RTP/RTCP 包结构图

IP 包头结构: TCP 包头结构: UDP 包头结构: RTP 包头结构: RTCP 包头结构:

你可能不知道的java、python、JavaScript以及jquary循环语句的区别

一.概述 java循环语句分为四种形式&#xff0c;分别是 while, do/while, for, foreach&#xff1b; python中循环语句有两种&#xff0c;while&#xff0c;for&#xff1b; JavaScript中循环语句有四种&#xff0c;while&#xff0c;do/while&#xff0c;for&#xff0c;for/in…

webservices系列(二)——JAX-WS文件上传下载

新建ImgData类&#xff0c;存放文件javabean DataHandler&#xff1a;使用这个类型存放文件 XmlRootElement(name"ImaData") XmlAccessorType(XmlAccessType.FIELD) public class ImgData {private Integer id;XmlMimeType("application/octet-stream")pri…

halcon sobel边缘检测sobel_amp

目录sobel_amp&#xff08;算子&#xff09;描述参数sobel_amp&#xff08;算子&#xff09; sobel_amp - 使用Sobel算子检测边缘&#xff08;幅度&#xff09;。 sobel_amp&#xff08;图片&#xff1a;边缘图像&#xff1a;滤波器方式&#xff0c;掩膜大小:) 描述 sobel_…

es中的一些知识点记录

1. forcemerge接口 强制段合并&#xff0c;设置为1时&#xff0c;是期望最终只有1个索引段。但实际情况是&#xff0c;合并的结果是段的总数会减少&#xff0c;但仍大于1&#xff0c;可以多次执行强制合并的命令。 设置的的目标值越小。合并消耗的时间会越久。 curl -XPOST htt…

用live555和ffplay搭建流媒体环境

用live555和ffplay搭建流媒体环境 http://bbs.chinavideo.org/viewthread.php?tid12166

如何才能优雅地书写JS代码

第一&#xff1a;关于匿名函数的使用 要避免全局变量泛滥&#xff0c; 可以考虑使用匿名函数&#xff0c; 把不需要在外部访问的变量或者函数限制在一个比较小的范围内。 例如以下代码&#xff1a; <script> function func1(){ var list ["a", "b",…

halcon hough_lines 霍夫直线变换

目录hough_lines&#xff08;算子&#xff09;描述参数hough_lines&#xff08;算子&#xff09; hough_lines - 借助Hough变换检测边缘图像中的线条并将其返回到HNF中。 hough_lines&#xff08;RegionIn :: AngleResolution&#xff0c;Threshold&#xff0c;AngleGap&…

通过border来实现各种三角符号

很长时间没有动笔了&#xff0c;最近学的东西很杂很乱&#xff01;又有点丢了西瓜捡芝麻&#xff0c;走马观花&#xff0c;瞻前顾后的感觉&#xff01; 因此&#xff0c;我决定一步步来&#xff0c;化繁为简&#xff0c;今天就从border入手。 很多时候我们都会需要一个三角形或…

MFC封装API

一、Win32Application Architecture 一个Win32 Application Architecture的代码结构如下&#xff1a; LRESULT CALLBACK WinWordsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); //定义回调处理消息函数 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPr…

通过阅读 Douglas Crockford 的源码学习如何写 JSON parser(一)

JSON-js Douglas Crockford 是 JSON 的发明者&#xff0c;所以通过 DC 的代码来学习 JSON 和 parser 绝对是上乘之选。这个仓库里面有四个 JS 文件&#xff0c;今天我们先研究 json_parse.js。 json_parse 定义了如下 API&#xff1a; json_parse(string) > object json_par…

halcon gen_region_hline 绘制霍夫变换提取直线

目录gen_region_hline&#xff08;算子&#xff09;描述gen_region_hline&#xff08;算子&#xff09; gen_region_hline - 将霍夫变换提取直线以普通形式描述的输入行存储为区域。 gen_region_hline( : Regions : Orientation, Distance : ) 描述 运算符gen_region_hline…

H.264视频RTP负载格式/NALU的类型

1. 网络抽象层单元类型(NALU) NALU 头由一个字节组成, 它的语法如下: |0|1|2|3|4|5|6|7| |F|NRI| Type | F: 1 个比特. forbidden_zero_bit&#xff1a;在H.264规范中规定了这一位必须为0。 NRI: 2 个比特. nal_ref_idc&#xff1…

4.10下午

转载于:https://www.cnblogs.com/yanyuying/p/6690662.html

虚函数

1、基于向上类型转换&#xff0c;基类通过虚函数可以对多个子类相似的功能实现统一管理。 2、例子&#xff1a; A为基类&#xff0c;B、C为A的同级子类。virtual只需在基类中标识一次&#xff0c;子类无需重复标识。class A {virtual void display(){cout<<"我是A&q…

Android绘制(一):来用shape绘出想要的图形吧!

目录 前言shape绘制矩形椭圆线环用shape绘制SeekBar最后前言 在没有UI设计师的时候, 或者是想简单看下效果的时候, 用shape进行快速绘制是极好的! 官方文档. shape绘制 一共有四种shape: rectangle, oval, line, ring. 矩形 我们一个一个来看, 首先是矩形: <?xml version&q…