计算几何+贪心

#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的更多相关文章

  1. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  2. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  3. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  4. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  5. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  6. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  7. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  8. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

  9. Nancy之Pipelines三兄弟(Before After OnError)

    一.简单描述 Before:如果返回null,拦截器将主动权转给路由:如果返回Response对象,则路由不起作用. After : 没有返回值,可以在这里修改或替换当前的Response. OnEr ...

随机推荐

  1. 解决安装失败的 Internet Explorer 11

    注意:这篇文章是由无人工介入的微软自动的机器翻译软件翻译完成.微软很高兴能同时提供给您由人工翻译的和由机器翻译的文章, 以使您能使用您的语言访问所有的知识库文章.然而由机器翻译的文章并不总是完美的.它 ...

  2. Python json解析

    #encoding: utf-8 ''' Author:Siukwan ''' import sys reload(sys) sys.setdefaultencoding('utf8') import ...

  3. template template parameter

    #include <iostream> using namespace std; template<typename T> class A { }; template<t ...

  4. [pinyin4j] java版汉字转换拼音(大小写)

    pinyin4J 是一个可以将汉字转换成拼音的lib,非常实用,其maven地址为:http://mvnrepository.com/artifact/com.belerweb/pinyin4j/2. ...

  5. IntelliJ IDEA 设置代码提示或自动补全的快捷键 (附IntelliJ IDEA常用快捷键)

    修改方法如下: 点击 文件菜单(File) –> 点击 设置(Settings- Ctrl+Alt+S), –> 打开设置对话框. 在左侧的导航框中点击 KeyMap. 接着在右边的树型框 ...

  6. 安装MySQL -- SuSE Linux Enterprise Server 11 SP3

    1.准备工作从MySQL官网上分别下载mysql服务器端于客户端包: MySQL-server-5.5.49-1.sles11.x86.rpm MySQL-client-5.5.49-1.sles11 ...

  7. angular中的cookie读写

    AngularJS中对cookie的操作封装了一个单独的模块,模块名为ngCookies,若想使用需在页面中先引入angular-cookies.js: <script src="js ...

  8. Linux下gcc,g++,gdb,scon部分用法笔记

    1 Ubuntu下编译安装GCC-4.1.2 拷贝gcc-4.1.2.tar.bz2(我下载的压缩文件)到/usr/local/src 解压 新生成的gcc-4.1.2这个目录被称为源目录,用${sr ...

  9. java中的反编译

    使用JD-GUI工具  支持mac os 和 windows  地址为:http://jd.benow.ca

  10. js得到当前页面的url信息方法

    js得到当前页面的url信息方法:http://www.cnblogs.com/zuosong160522/p/5755615.html js获取url传递参数,js获取url?后面的参数:http: ...