计算几何+贪心

#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. Java重写与重载之间的区别

    重写(Override) 重写是子类对父类的允许访问的方法的实现过程进行重新编写, 返回值和形参都不能改变.即外壳不变,核心重写! 重写的好处在于子类可以根据需要,定义特定于自己的行为. 也就是说子类 ...

  2. <span>什么意思

    <span> 在CSS定义中属于一个行内元素,在行内定义一个区域,也就是一行内可以被 <span> 划分成好几个区域,从而实现某种特定效果. <span> 本身没有 ...

  3. table排名次

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. redis服务器安装-SuSE Linux Enterprise Server 11 SP3

    一.下载 官网下载,可自选版本,点击进入下载,这里下载了redis-3.2.4 放到 /root/usr/local/redis/ 目录下 二.编译 1. 执行make编译redis tar -zxz ...

  5. Smail语法

    1.数据类型 2.函数: Func-Name (Para-Type1Para-Type2Para-Type3...)Return-Type 注意参数与参数之间没有任何分隔符 3.函数调用: 4.关于s ...

  6. HMM 前向后向算法(转)

    最近研究NLP颇感兴趣,但由于比较懒,所以只好找来网上别人的比较好的博客,备份一下,也方便自己以后方便查找(其实,一般是不会再回过头来看的,嘿嘿 -_-!!) 代码自己重新写了一遍,所以就不把原文代码 ...

  7. Tomcat启动时报错:java.net.UnknownHostException

    异常信息如下: INFO: Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll ad ...

  8. 啥数据类型set补充、深浅拷贝与函数

    #s1 = {1,2,3,1} """ s2 = ([2,5,6]) print(s1) s1.add(5) #添加元素"5" print(s1) s ...

  9. Reprint: Serialization

    Having just recently ran into some major serialization issues I’m going to list some of the errors a ...

  10. 获取usb设备父系或子代

    /// <summary> /// 获取设备父系 /// </summary> /// <param name="driver"></pa ...