A - Piece of Cake Kattis - pieceofcake (数学)

题目链接:

A - Piece of Cake

Kattis - pieceofcake

题目大意:给你一个多边形,然后给你这个多边形的每个点的坐标,让你从这个n个点中选出k个点,问这个k个点形成的面积的期望。

具体思路:我们肯定不能硬跑每一个k边形,肯定会超时。我们以每个点作为起点,从这个点开始,形成的面积的期望是多少,然后遍历每一个点,这样算出来的会有重复,最后除以2就可以了。

然后算面积的时候,我们分开算。一个多边形的面积等于每个点按照顺时针或者是逆时针两个点之间的叉积。

求组合数的时候,用递推的方法。

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 # define ll long long
 4 # define inf 0x3f3f3f3f
 5 const int maxn = 2e5+100;
 6 struct node{
 7 long  double  x,y;
 8 }q[maxn];
 9 long double  cal(int t1,int t2){
10 return (q[t1].x*q[t2].y-q[t1].y*q[t2].x);
11 }
12 long double c[3000][3000];
13 int main(){
14 int n,k;
15 scanf("%d %d",&n,&k);
16 for(int i=0;i<n;i++){
17 cin>>q[i].x>>q[i].y;
18 }
19 for(int i=0;i<=n;i++){
20 c[0][i]=0;
21 c[i][0]=1;
22 }
23 for(int i=1;i<=n;i++){
24 for(int j=1;j<=i;j++){
25 c[i][j]=c[i-1][j]+c[i-1][j-1];
26 }
27 }
28 long double  ans=0;
29 for(int i=0;i<n;i++){
30 for(int j=k-1;j<n;j++){
31 int  to=(i+j)%n;
32 ans+=cal(i,to)*c[j-1][k-2]/c[n][k];
33 //cout<<cal(i,to)<<" "<<c[j-1][k-1]<<" "<<c[n][k]<<endl;
34 }
35 }
36 //cout<<ans<<endl;
37 ans/=2.0;
38 cout<<fixed<<setprecision(6)<<ans<<endl;
39 }

原文地址:https://www.cnblogs.com/letlifestop/p/10676011.html

时间: 2024-11-10 11:36:41

A - Piece of Cake Kattis - pieceofcake (数学)的相关文章

Jarvis OJ A Piece Of Cake

看图片的隐写术自闭,本来想看一看jarvisoj 的basic放松一下心情,结果一道题就做了一晚上qwq 首先看到这道题的时候想到的是凯撒密码(这其实是Google之后才知道这个名字的)枚举了26种位移,发现都不可读. 心态爆炸,只能猜到是以一种奇怪的方式做一一替换后的结果,依稀想起了之前听说过的词频分析法,不会操作,就可耻地看了题解. get提示替换式密码,而且题目十分良心地没有去掉空格,难度下降了不少,有单独的一个x,推测是a,nit出现的次数极多,推测是the,在python中不断地替换,

JarvisOJ-A Piece Of Cake

Problem Description nit yqmg mqrqn bxw mtjtm nq rqni fiklvbxu mqrqnl xwg dvmnzxu lqjnyxmt xatwnl, rzn nit uxnntm xmt zlzxuuk mtjtmmtg nq xl rqnl. nitmt vl wq bqwltwlzl qw yivbi exbivwtl pzxuvjk xl mqrqnl rzn nitmt vl atwtmxu xamttetwn xeqwa tsftmnl,

题解[CodeForces171C]A Piece of Cake

Description 给你\(n\)个数,求出\(\sum_{i=1}^{n} a_{i}\times i\qquad\) Input 共\(n + 1\)个数,分别为\(n\)和\(n\)个数\(a_{i}\)(\(1\)\(\leq i \le n\)). Output \(\sum_{i=1}^{n} a_{i}\times i\qquad\) Examples Input 4 1 2 3 4 Output 30 Solution 根据题目翻译可知:这是一道模拟题. 首先,输入一个整数\

POJ1020 Anniversary Cake

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16683   Accepted: 5442 Description Nahid Khaleh decides to invite the kids of the "Shahr-e Ghashang" to her wedding anniversary. She wants to prepare a square-shaped chocolate cake wit

HDOJ 4454 Stealing a Cake 计算几何

暴力枚举角度..... Stealing a Cake Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2495    Accepted Submission(s): 681 Problem Description There is a big round cake on the ground. A small ant plans to

【DFS】Anniversary Cake

[poj1020]Anniversary Cake Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17203   Accepted: 5619 Description Nahid Khaleh decides to invite the kids of the "Shahr-e Ghashang" to her wedding anniversary. She wants to prepare a square

HDU 4454 Stealing a Cake(三分暴力枚举)

题目大意:给你一个点,一个圆,一个矩形让你求出来,点到圆然后再到矩形的距离.圆和矩形你可以认为是可以穿过的. 解题思路:三分枚举点到圆的位置,然后求出来总长度,找到一个最小的长度.枚举点的坐标的时候可以枚举角度,也可以枚举坐标.总长度等于点到圆上的点的距离加上圆上的点到矩形四个线段的最小距离的和. PS:输出%0.2lf所以精度要求不高,自我感觉枚举角度会更保证精度. Stealing a Cake Time Limit: 5000/2000 MS (Java/Others)    Memory

Anniversary Cake

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15704   Accepted: 5123 Description Nahid Khaleh decides to invite the kids of the "Shahr-e Ghashang" to her wedding anniversary. She wants to prepare a square-shaped chocolate cake wit

poj1020 Anniversary Cake 搜索

Description Nahid Khaleh decides to invite the kids of the "Shahr-e Ghashang" to her wedding anniversary. She wants to prepare a square-shaped chocolate cake with known size. She asks each invited person to determine the size of the piece of cak