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 ...
随机推荐
- Java SE ——TCP协议网络编程(三)
之前的代码中关闭了 socket 对象的输入流与输出流,但并没有关闭掉socket 对象,会造成服务器资源的浪费,应通过调用 socket 的 close() 方法来关闭当前的socket 对象. 因 ...
- C#-实验3
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 曾经让我很吐血的Bug(初学者)
1.MSSql 就是 sql Server. 2.用session的时候一定要先实现接口IRequiresSessionState: 3.form表单中type=file传送文件的时候一定要在form ...
- QGIS
project(GisFreeMap) set(CMAKE_BUILD_TYPE Debug) find_package(Qt4 REQUIRED QtCore QtGui QtXml) includ ...
- 常见的 http 状态码
1~5开头的HTTP状态码分别表示: 1XX 表示消息 2XX 表示成功 3XX 表示重定向 4XX 表示请求错误 5XX 表示服务端错误 常见的HTTP状态码: 200 OK 表示请求成功 一切正常 ...
- for for-in foreach 循环
var a = [1, 2, 3, 4, 5] //for用来便利数组元素非常简单 for (var i = 0; i < a.length; i++) { console.log(a[i]) ...
- 安卓平台多个视频叠加演示demo说明
多个音视频编辑演示说明: 第一个-----字幕和视频的叠加: 说明: 把字幕文件中的文字,按照时间叠加到视频上去,形成新的视频. 类似我们看电影时的字幕. 下载地址:http://www.cnblog ...
- 生成 Qt 文档
个人总结 从命令行进入Qt安装目录 设置环境变量 set path=D:/mingw32/bin;D:/Qt/5.0.0/qtbase/bin;D:/icu/bin;D:/icu ...
- Action3D
抖动效果-Shaky3D 波浪效果-Waves3D 翻转效果-FlipX3D 凸镜效果-Ripple3D 液体效果-Liquid 扭动效果-Twirl 破碎效果-ShatteredTiles3D 瓷砖 ...
- IBM Minus One
IBM Minus One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...