水题,就是把一个矩形平分。

题意:一个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;
}

  

最新文章

  1. 【Win10 应用开发】集成文件打开选择器
  2. SpringBean_获取Spring加载的所有bean(实践)
  3. 使用js设置input标签只读 readonly 属性
  4. [反编译U3D]Decompile Unity Resources
  5. iOS 利用Context裁剪图片
  6. jquery mobile 请求数据方法执行时显示加载中提示框
  7. UEFI引导修复教程和工具
  8. Nginx log
  9. CH Round #55 - Streaming #6 (NOIP模拟赛day2)
  10. &lt;jsp:directive.page&gt;标签
  11. Android中的AutoCompleteTextView的使用
  12. Chapter 2 User Authentication, Authorization, and Security(6):服务器权限授予粒度
  13. sql_calc_found_rows原理
  14. Mysql partition by
  15. Windows 查看某个端口号是否被占用
  16. Nginx反向代理tomcat返回400 bad request
  17. Ngui使用随心记
  18. Django 2.0.1 官方文档翻译:编写你的第一个djang补丁(page 15)
  19. caffe添加自己编写的Python层
  20. Tomcat指定JDK路径(Linux+Windows)

热门文章

  1. Python入门 六、像个 Pythonista
  2. JDK5.0新特性(静态导入、自动装箱/拆箱、增强for循环、可变参数、枚举、泛形)
  3. JSP页面中path和basepath的含义
  4. 前端-Vue学习思维导图笔记
  5. Leetcode0002--Add Two Numbers 链表求和
  6. WEB笔记-2 剖析CSS规则
  7. Windows-Server-2008、IIS7.0环境下配置伪静态化
  8. Python学习①. 基础语法
  9. Maven常见异常及解决方法
  10. react-draft-wysiwyg富文本