ZOJ 2710 Two Pipelines
计算几何+贪心
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; struct City
{
int id;
double J1;//距离第一条
double J2;//距离第二条
double X,Y;
double C;
int be;//属于哪一条
double xuqiu; } node[];
int n,c;
int shu1,shu2; bool cmpid(const City&a,const City&b) //按照城市编号排序
{
return a.id<b.id;
}
bool cmpbe(const City&a,const City&b) //按照归属分层
{
return a.be<b.be;
}
bool cmpC(const City&a,const City&b) //按照差值排序
{
return a.C<b.C;
} int main()
{
int i;
while(~scanf("%d%d",&n,&c))
{
shu1=,shu2=;
double x1,y1,x2,y2;
double x3,y3,x4,y4;
double A1,B1,C1;
double A2,B2,C2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
scanf("%lf%lf%lf%lf",&x3,&y3,&x4,&y4);
A1=y2-y1;
A2=y4-y3;
B1=x1-x2;
B2=x3-x4;
C1=x2*y1-x1*y2;
C2=x4*y3-x3*y4;
for(i=; i<n; i++)
scanf("%lf%lf%lf",&node[i].X,&node[i].Y,&node[i].xuqiu);
for(i=; i<n; i++)
{
node[i].J1=fabs(A1*node[i].X+B1*node[i].Y+C1)/sqrt(A1*A1+B1*B1);
node[i].J2=fabs(A2*node[i].X+B2*node[i].Y+C2)/sqrt(A2*A2+B2*B2);
if(node[i].J1<=node[i].J2) node[i].be=,shu1++;
else node[i].be=,shu2++;
node[i].C=fabs(node[i].J1-node[i].J2)*node[i].xuqiu;
node[i].id=i;
}
if(abs(shu1-shu2)<=c)
{
for(i=; i<n; i++)
{
if(i<n-) printf("%d ",node[i].be);
else printf("%d\n",node[i].be);
}
}
else
{
int fenjie=-;
sort(node,node+n,cmpbe);
for(i=; i<n; i++) if(node[i].be==) break;
fenjie=i-;
if(shu1>shu2)
{
sort(node,node+fenjie+,cmpC);
int yidong=;
for(i=; i<=fenjie; i++)
{
node[i].be=;
shu1--;
shu2++;
if(abs(shu1-shu2)<=c) break;
}
sort(node,node+n,cmpid);
for(i=; i<n; i++)
{
if(i<n-) printf("%d ",node[i].be);
else printf("%d\n",node[i].be);
}
}
else
{
sort(node+fenjie+,node+n,cmpC);
int yidong=;
for(i=fenjie+; i<=n-; i++)
{
node[i].be=;
shu1++;
shu2--;
if(abs(shu2-shu1)<=c) break;
}
sort(node,node+n,cmpid);
for(i=; i<n; i++)
{
if(i<n-) printf("%d ",node[i].be);
else printf("%d\n",node[i].be);
}
}
}
}
return ;
}
ZOJ 2710 Two Pipelines的更多相关文章
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
- Nancy之Pipelines三兄弟(Before After OnError)
一.简单描述 Before:如果返回null,拦截器将主动权转给路由:如果返回Response对象,则路由不起作用. After : 没有返回值,可以在这里修改或替换当前的Response. OnEr ...
随机推荐
- JavaScript :memory leak [转]
Memory leak patterns in JavaScript Handling circular references in JavaScript applications Abhijeet ...
- static const readonly
C#中的static 和Java中的static 简单,两者用法完全是一致的.从两方面讨论: 1. 变量是属于类的,不是实例级别的.只能通过类名调用,不能通过实例调用. 2. 如果在定义时就赋值了,那 ...
- PHP定义静态方法的原则
与实例逻辑无关 与类逻辑有关 静态类本质上跟纯函数没区别. 1.static方法是类中的一个成员方法,属于整个类,即使不用创建任何对象也可以直接调用! 2.静态方法效率上要比实例化高,静态方法的缺点是 ...
- Front-End(一)
前端初识 现在网站开发的市场越来越大,个人和企业都有了主页.网络办公的需求,并且随着网站开发前端和后台的工作细分,前端开发的需求也越来越大. 前端的任务是将美工的网页设计使用前端技术尽可能无差别地实现 ...
- hdu1116回溯N皇后问题
题目连接 经过思考,不难发现:恰好N个皇后放在不同行不同列,那么是不是可以转换成N个皇后所在行分别确定(一人一行)的情况下对她们的所在列的枚举. 也就是列的全排列生成问题,我们用c[x]表示x行皇后的 ...
- 自定义dialog自动弹出软键盘
1.解决无法弹出输入法: 在show()方法调用之前,用dialog.setView(new EditText(context))添加一个空的EditText,由于是自定义的AlertDialog,有 ...
- shell中bash的常见命令
shell 在计算机科学中,Shell俗称壳,用来区别Kernel(核) Shell分类:1:图形界面shell:通过提供友好的可视化界面,调用相应应用程序,如windows系列操作系统,Linux系 ...
- 使用ab对站点进行压力测试
测试指令: window下: E:\wamp\bin\apache\Apache2.2.21\bin> .\ab -V //查看是否按照了ab:(V 大写) E:\wamp\bin\apach ...
- PHPStorm 安装 SASS、SCSS + Compass
许久没更新博客啦,这两天研究了下 SASS 和 LESS ,最终选了 SASS,因为相对比较成熟些吧,试了很多坑之后,终于成功了,下面上步骤: 1. 安装 PHPStorm 的 SASS 插件 好像是 ...
- 在GNU/Linux下使用命令行自动挂载与卸载USB磁盘
在命令行环境下如果每次都是靠手动敲入mount与umount命令来挂载与卸载USB磁盘是件很麻烦的事情.尤其是mount命令的参数非常多.比如,磁盘的分区类型(vfat.ntfs等),挂载的目录节点, ...