求助不知道哪里错了
查看原帖
求助不知道哪里错了
489327
小熙熙楼主2024/5/24 20:19

悬赏十元,加数之迷投币20

/*
Wzx's code.
Love has a nasty habit of disappearing over night.
But I love you forever.
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define ll long long
#define double long double 
#define bug cout<<"bug"<<"\n"
#define mk make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define fo(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define ls (p<<1)
#define rs (p<<1|1)
using namespace std;
const ll maxn=4e5+100;
const ll inf=0x3f3f3f3f;
const double eps=1e-9;
const ll mod=1e9+7;
inline ll rd(){ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int T;
int n,k; 
struct node{
	double x,y;
}a[maxn];
double S(double x1,double y1,double x2,double y2,double x3,double y3){
	return 0.5*fabs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1));
}
double diss(double x1,double y1,double x2,double y2,double x0,double y0){
	if(x1==x2){return fabs(x0-x1);}
	if(y1==y2){return fabs(y0-y1);}
	double t=sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
	double tt=fabs((y1-y2)*x0-(x1-x2)*y0-(y1-y2)*x2+(x1-x2)*y2);
	return (tt/t);
}
double dis(double x1,double y1,double x2,double y2){
	return sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
}
int main(){
	cin>>T;
	while(T--){
		cin>>n>>k;
		for(int i=1;i<=n;i++){a[i].x=rd(),a[i].y=rd();}
		for(int i=n+1;i<=n+n;i++){a[i].x=a[i-n].x,a[i].y=a[i-n].y;}
		double Ss=0;
		for(int i=1;i<=k-1;i++){Ss+=S(a[k+1].x,a[k+1].y,a[i].x,a[i].y,a[i+1].x,a[i+1].y);}
		int fr=k+2;
		double maxx=0;
		for(int i=1;i<=n;i++){
			int b=i,c=i+k;
			for(int j=fr+1;j<=n+n;j++){
				double t=diss(a[b].x,a[b].y,a[c].x,a[c].y,a[j].x,a[j].y);
				double tt=diss(a[b].x,a[b].y,a[c].x,a[c].y,a[fr].x,a[fr].y);
				if(t<tt||(fabs(t-tt)<eps)) break;
				else fr=j;
			}
			double t1=dis(a[b].x,a[b].y,a[c].x,a[c].y),t2=diss(a[b].x,a[b].y,a[c].x,a[c].y,a[fr].x,a[fr].y);
			maxx=max(maxx,(Ss+0.5*t1*t2));
			Ss-=S(a[b].x,a[b].y,a[b+1].x,a[b+1].y,a[c].x,a[c].y);
			Ss+=S(a[b+1].x,a[b+1].y,a[c].x,a[c].y,a[c+1].x,a[c+1].y);			
		}
		printf("%.10Lf\n",maxx);
	} 
	return 0;
}
/*



                                        _ooOoo_
                                       o8888888o
                                       88" . "88
                                       (| -_- |)
                                       O\  =  /O
                                    ____/`---'\____
                                  .'  \\|     |//  `.
                                 /  \\|||  :  |||//  \
                                /  _||||| -:- |||||-  \
                                |   | \\\  -  /// |   |
                                | \_|  ''\---/''  |   |
                                \  .-\__  `-`  ___/-. /
                              ___`. .'  /--.--\  `. . __
                           ."" '<  `.___\_<|>_/___.'  >'"".
                          | | :  `- \`.;`\ _ /`;.`/ - ` : | |
                          \  \ `-.   \_ __\ /__ _/   .-` /  /
                     ======`-.____`-.___\_____/___.-`____.-'======
                                        `=---='
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    				 保佑此题不挂分
*/


2024/5/24 20:19
加载中...