链接:https://ac.nowcoder.com/acm/contest/52244/B 来源:牛客网 现在小龙同学要吃掉它们,已知他有nn颗苹果,并且打算每天吃一个。 但是古人云,早上金苹果,晚上毒苹果。由此可见,早上吃苹果和晚上吃苹果的效果是不一样的。 已知小龙同学在第 ii 天早上吃苹果能获得的愉悦值为 a_ia i ,晚上吃苹果能获得的愉悦值为 b_ib i 。 但是为了饮食均衡,小龙同学决定必须能选择恰好kk 天晚上吃苹果。 剩下的 n-kn−k 天早上吃苹果,他想知道他能够获得最大的愉悦值是多少。 
时间: 2023-04-06 09:02:28 浏览: 110
我可以回答这个问题。这是一个算法问题,需要使用动态规划来解决。具体来说,可以定义一个二维数组dp[i][j]表示前i天中恰好选j天晚上吃苹果所能获得的最大愉悦值。然后根据题目给出的条件,可以得到状态转移方程:dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]+b[i]),其中b[i]表示第i天晚上吃苹果所能获得的愉悦值。最终答案即为dp[n][k]。
相关问题
https://ac.nowcoder.com/acm/contest/61657/L
根据提供的引用内容,我无法回答你的问题。引用内容中包含了一些代码和链接,但没有提供具体的问题描述。请提供更详细的问题描述,我将尽力帮助你解答。
#### 引用[.reference_title]
- *1* *3* [2022/7/17/题解2022河南萌新联赛第(二)场:河南理工大学https://ac.nowcoder.com/acm/contest/37344](https://blog.csdn.net/m0_66433418/article/details/125835437)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [牛客·金币https://ac.nowcoder.com/acm/contest/19305/1021](https://blog.csdn.net/m0_66433418/article/details/125787020)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
链接:https://ac.nowcoder.com/acm/contest/52441/E 来源:牛客网 给定n 个不重复的坐标,求其中 3个坐标能表示一个等腰三角形的组数。 三点共线不算三角形,等边三角形为特殊的等腰三角形。用c++实现
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=10005;
const double eps=1e-8;
struct point
{
double x,y;
friend bool operator<(const point &a,const point &b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
friend point operator+(const point &a,const point &b)
{
return point{a.x+b.x,a.y+b.y};
}
friend point operator-(const point &a,const point &b)
{
return point{a.x-b.x,a.y-b.y};
}
friend point operator*(const point &a,double b)
{
return point{a.x*b,a.y*b};
}
friend point operator/(const point &a,double b)
{
return point{a.x/b,a.y/b};
}
friend double operator*(const point &a,const point &b)
{
return a.x*b.y-a.y*b.x;
}
}p[N],st[N],st2[N];
int top=0,top2=0,n,ans;
double len[N],sum[N];
inline double dist(const point &a,const point &b)
{
double x=a.x-b.x,y=a.y-b.y;
return sqrt(x*x+y*y);
}
inline void tubao()
{
for(int i=1;i<=n;++i)
{
while(top&&p[i].y<=st[top].y) --top;
st[++top]=p[i];
}
for(int i=1;i<=n;++i)
{
while(top2&&p[i].y>=st2[top2].y) --top2;
st2[++top2]=p[i];
}
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p+1,p+n+1);
tubao();
for(int i=1;i<=top;++i)
st[i+top]=st[i];
for(int i=1,j=1,k=1;i<=top;++i)
{
while(dist(st[i],st[j])<dist(st[i],st[j+1]))
j=j%top+1;
while(k+1<i+top&&((st[i]-st[j])*(st[i]-st[k+1]))>((st[i]-st[j])*(st[i]-st[k])))
k=k%top+1;
len[i]=dist(st[i],st[j]);
sum[i]=sum[i-1]+len[i];
while(sum[i]-sum[j-1]>len[i]+eps) ++j;
if(st[i].y==st[j].y) continue;
double a=dist(st[i],st[j]),b=dist(st[j],st[k]),c=dist(st[i],st[k]),p=(a+b+c)/2;
if(fabs(b*b+c*c-a*a)<eps)
ans+=upper_bound(sum+i,sum+top2+1,sum[i-1]+len[i]/2)-lower_bound(sum+i,sum+top2+1,sum[i-1]-len[i]/2);
else continue;
}
printf("%d\n",ans);
return 0;
}
相关推荐















