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 ...
随机推荐
- [ios2]ios RSA
http://blog.iamzsx.me/show.html?id=155002 http://www.theosoft.net/ http://blog.sina.com.cn/s/blog_5f ...
- Caffe安装过程错误处理方法
1. 错误1: fatal error: caffe/proto/caffe.pb.h: No such file or directory 解决方法: You need to generate ca ...
- [CSS] 子元素垂直居中的两种方式
1. 多个子元素水平并排,IE10以下失效 display: flex; align-items: center; justify-content: center; 2.多个子元素竖直排列,这种方式会 ...
- Mutex的使用方法以及封装的AutoLock介绍(转载)
Mutex-互斥类 互斥类-MutexMutex是互斥类,用于多线程访问同一个资源的时候,保证一次只有一个线程能访问该资源.在<Windows核心编程>①一书中,对于这种互斥访问有一个很形 ...
- Android学习---- 十月
//因为域名去备案了 //PHP的学习想停一下,刚好说什么Java要开始实验课了 //暑假看的Java都生疏了,就想顺便学一下Android,熟悉一下Java的语法也好,顺便学学新东西 //昨天域名备 ...
- spark yarn任务的executor 无故 timeout之原因分析
问题: 用 spark-submit --master yarn --deploy-mode cluster --driver-memory 2G --num-executors 6 --execu ...
- noip 2016 提高组题解
前几天写的那个纯属搞笑.(额,好吧,其实这个也不怎么正经) 就先说说day2吧: T1:这个东西应该叫做数论吧. 然而我一看到就照着样例在纸上推了大半天(然而还是没有看出来这东西是个杨辉三角) 然后就 ...
- Tiny6410之MMU开启
存储管理单元存储管理单元MMU概述 在ARM系统中,存储管理单元MMU主要完成以下工作:1.虚拟存储空间到物理存储空间的映射.在ARM中采用页式虚拟存储管理.他把虚拟地址空间分成一个个固定大小的块,每 ...
- Another Array of Orz Pandas
Another Array of Orz Pandas 题目链接:http://acm.xidian.edu.cn/problem.php?id=1187 线段树 线段树维护区间和以及区间内各个数平方 ...
- Interrupts