HDU 3432
2024-08-23 03:14:31
水题,就是把一个矩形平分。
题意:一个wid*hei的矩形,过底边上的一点(dor,0)做m-1条射线,把这个矩形的面积平均分成m份,求这些射线和矩形的另外一个交点。
直接枚举,然而求三角形高底移动坐标即可。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath> using namespace std;
struct pointer {
double x,y;
}ans[120];
const double eps=0.00000001; int main(){
int wid,heg,door,p;
while(scanf("%d%d%d%d",&wid,&heg,&door,&p)!=EOF){
if(wid==0&&heg==0&&door==0&&p==0) break;
double ye=0,xe=wid,ys=heg;
double parea=(wid*heg)*1.0/p;
double part1=(wid-door)*heg*1.0/2;
double part2=wid*heg*1.0/2;
double part3=(door)*heg*1.0/2;
double tmp;
for(int i=0;i<p;i++){
tmp=parea;
if(part1>eps){
if(tmp-eps>part1){
tmp-=part1;
part1=0;
}
else if(fabs(tmp-part1)<=eps){
ans[i].x=wid; ans[i].y=heg;
part1=0;
continue;
}
else {
double yy=(tmp*2)/(wid-door);
ye+=yy;
ans[i].x=wid; ans[i].y=ye;
part1-=tmp;
continue;
}
}
if(part2>eps){
if(tmp-eps>part2){
tmp-=part2;
part2=0;
}
else if(fabs(tmp-part2)<=eps){
ans[i].x=0; ans[i].y=heg;
part2=0;
continue;
}
else {
double xx=(tmp*2)/heg;
xe-=xx;
ans[i].x=xe; ans[i].y=heg;
part2-=tmp;
continue;
}
}
if(part3>eps){
if(tmp-eps>part3){
tmp-=part3;
part2=0;
}
else if(fabs(tmp-part3)<=eps){
ans[i].x=0; ans[i].y=0;
part3-=0;
continue;
}
else{
double yy=(tmp*2)/door;
ys-=yy;
ans[i].x=0; ans[i].y=ys;
part2-=tmp;
continue;
}
}
}
printf("%.3lf %.3lf",ans[0].x,ans[0].y);
for(int i=1;i<p-1;i++){
printf(" %.3lf %.3lf",ans[i].x,ans[i].y);
}
printf("\n");
}
return 0;
}
最新文章
- 【Win10 应用开发】集成文件打开选择器
- SpringBean_获取Spring加载的所有bean(实践)
- 使用js设置input标签只读 readonly 属性
- [反编译U3D]Decompile Unity Resources
- iOS 利用Context裁剪图片
- jquery mobile 请求数据方法执行时显示加载中提示框
- UEFI引导修复教程和工具
- Nginx log
- CH Round #55 - Streaming #6 (NOIP模拟赛day2)
- <;jsp:directive.page>;标签
- Android中的AutoCompleteTextView的使用
- Chapter 2 User Authentication, Authorization, and Security(6):服务器权限授予粒度
- sql_calc_found_rows原理
- Mysql partition by
- Windows 查看某个端口号是否被占用
- Nginx反向代理tomcat返回400 bad request
- Ngui使用随心记
- Django 2.0.1 官方文档翻译:编写你的第一个djang补丁(page 15)
- caffe添加自己编写的Python层
- Tomcat指定JDK路径(Linux+Windows)