【bzoj1027】合金

分析

数形结合+计算几何+Floyd最小环。

http://blog.csdn.net/popoqqq/article/details/40539273

虽然这样占大家的很不好,但是我的确需要这么做。

小结

(1)最小环的写法

(2)凸包的一种简易算法

RT。

(3)关于计算几何的练习

通过做这道题,计算几何的模板也熟悉了一些。

计算几何如何调试?

这个么...好像只能瞪眼法了。

代码

#include <cstdio>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;

#define rep(i,a,b) for (int i=(a);i<=(b);i++)

const int M=512;
const int N=512;
const int MAX=INT_MAX>>1;
const double EPS=1e-15;

int cmp(double x);

int m,n;
struct point
{
    double x,y;
    point(double _x=0,double _y=0) {
        x=_x,y=_y;
    }
    friend point operator - (point a,point b) {
        return point(a.x-b.x,a.y-b.y);
    }
    friend point operator * (point a,point b) {
        return point(a.x*b.x,a.y*b.y);
    }
    friend int operator == (point a,point b) {
        return !cmp(a.x-b.x)&&!cmp(a.y-b.y);
    }
    friend int operator != (point a,point b) {
        return !(a==b);
    }
}mer[M],prd[N];

int f[M][M];
int res;

void Init(void) {
    scanf("%d%d",&m,&n);
    rep(i,1,m) {
        double x,y; scanf("%lf%lf%*lf",&x,&y);
        mer[i]=point(x,y);
    }
    rep(i,1,n) {
        double x,y; scanf("%lf%lf%*lf",&x,&y);
        prd[i]=point(x,y);
    }
}

int cmp(double x)
{
    if(fabs(x)<EPS)  return 0;
    return x>0?1:-1;
}

double det(point a,point b) {
    return a.x*b.y-a.y*b.x;
}

int Left(point k,point a,point b) {
    double t=det(b-a,k-a);
    return t>0;
}
int On(point k,point a,point b) {
    if (cmp(det(k-a,b-a))!=0) return 0;
    if (!(cmp(min(a.x,b.x)-k.x)<=0&&cmp(k.x-max(a.x,b.x))<=0)) return 0;
    if (!(cmp(min(a.y,b.y)-k.y)<=0&&cmp(k.y-max(a.y,b.y))<=0)) return 0;
    return 1;
}

/*
bool On(const point &a,const point &b,const point &c) {
    return !cmp(det(a-b,c-b))&&cmp((a.x-b.x)*(a.x-c.x))<=0&&cmp((a.y-b.y)*(a.y-c.y))<=0;
}
*/

int Check(point a,point b) {
    rep(i,1,n) {
        int t1=Left(prd[i],a,b);
        int t2=On(prd[i],a,b);
        if (!t1&&!t2) return 0;
    }
    return 1;
}

void MakeGraph(void) {
    rep(i,1,m) rep(j,1,m) f[i][j]=MAX;
    rep(i,1,m) rep(j,1,m)
        if (Check(mer[i],mer[j]))
            f[i][j]=1;
}

int Floyd(void) {
    rep(i,1,m) {
        int mrk=1;
        rep(j,1,n) if (mer[i]!=prd[j]) {
            mrk=0;
            break;
        }
        if (mrk) return 1;
    }

    rep(i,1,m) rep(j,1,m) {
        int mrk=1;
        rep(k,1,n)
            if (!On(prd[k],mer[i],mer[j])) {
                mrk=0;
                break;
            }
        if (mrk) return 2;
    }

    /*
    rep(i,1,m) {
        rep(j,1,m)
            if (f[i][j]!=MAX)
                printf("%d ",f[i][j]);
            else printf("0 ");
        printf("\n");
    }
    */

    int ans=MAX;
    rep(k,1,m) rep(i,1,m) rep(j,1,m)
        f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
    rep(i,1,m) ans=min(ans,f[i][i]);
    return ans!=MAX?ans:-1;
}

int main(void) {
    #ifndef ONLINE_JUDGE
    freopen("bzoj1027.in","r",stdin);
    freopen("bzoj1027.out","w",stdout);
    #endif

    Init();
    MakeGraph();

    res=Floyd();
    printf("%d\n",res);

    return 0;
}

【bzoj1027】合金的更多相关文章

  1. bzoj1027【JSOI2007】合金

    题目描述 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的合金.新的合金 ...

  2. bzoj1027 [JSOI2007]合金

    1027: [JSOI2007]合金 Time Limit: 4 Sec  Memory Limit: 162 MBSubmit: 2671  Solved: 703[Submit][Status][ ...

  3. bzoj千题计划123:bzoj1027: [JSOI2007]合金

    http://www.lydsy.com/JudgeOnline/problem.php?id=1027 因为x+y+z=1,所以z=1-x-y 第三维可以忽略 将x,y 看做 平面上的点 简化问题: ...

  4. BZOJ1027 [JSOI2007]合金 【计算几何 + floyd】

    题目 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的 原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的合金.新的合金的 ...

  5. [bzoj 1027][JSOI2007]合金(解析几何+最小环)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1027 分析: 首先因为一个合金的和为1,所以考虑2个材料合金能否合成一个需求合金的时候 ...

  6. 合金装备V 幻痛 制作技术特辑

    合金装备V:幻痛 制作特辑 资料原文出自日版CGWORLD2015年10月号   在[合金装备4(Metal Gear Solid IV)]7年后,序章作品[合金装备5 :原爆点 (Metal Gea ...

  7. 【BZOJ】【1027】【JSOI2007】合金

    计算几何/凸包/Floyd Orz rausen大爷太强辣 计算几何题目果然不会做>_> 这个题……虽然他给了3个坐标,但实际上是个二维的计算几何题= =因为第三维坐标可以直接用前两维坐标 ...

  8. 1027: [JSOI2007]合金 - BZOJ

    Description 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的 ...

  9. BZOJ_1027_[JSOI2007]_合金_(计算几何+Floyd求最小环)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1027 共三种金属,\(m\)种材料,给出每种材料中三种金属的占比. 给出\(n\)种合金的三种 ...

随机推荐

  1. 在WIn32程序中使用MFC的CInternetSession运行异常,主要是因为获取目前应用程序名出错的解决办法

    转载:http://group.gimoo.net/review/22564 头文件#include <afxinet.h"> 在非MFC工程中使用CInternetSessio ...

  2. 【leetcode❤python】342. Power of Four

    #-*- coding: UTF-8 -*- class Solution(object):    def isPowerOfFour(self, num):        ""& ...

  3. ZOJ 2182 Cable TV Network(无向图点割-最大流)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2182 题意:给出一个无向图,问最少删掉多少个顶点之后图变得不连通 ...

  4. DirectX 3d 取景变换

    在世界坐标系中,几何体和摄像机都是相对于世界坐标系定义的.但是当摄像机的位置和朝向任意时,投影变换及其它类型的变的就略显困难或效率不高.为了简化运算,我们将摄像机变的至世界坐标系原点,并将其旋转,使摄 ...

  5. DLL输入和输出函数—dllinport与dllexport

    Microsoft特殊处 dllimport和dllexport存储类修饰符是C语言的Microsoft特殊处扩充.这些修饰显式定义了DLL的客户界面(可执行的文件或另外的DLL).说明为dllexp ...

  6. HashCheck

    https://github.com/gurnec/HashCheck

  7. DJANGO基础学习之转义总结:escape,autoescape,safe,mark_safe

    何谓转义?就是把html语言的关键字过滤掉.例如,<div>就是html的关键字,如果要在html页面上呈现<div>,其源代码就必须是<div> PS:转义其实就 ...

  8. windows下安装zabbix_agents_2.2.0

    下载与解压 下载zabbix_agents_2.2.0 http://www.zabbix.com/downloads/2.2.0/zabbix_agents_2.2.0.win.zip 解压到C盘下 ...

  9. hdu 1217 (Floyd变形)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1217 Arbitrage Time Limit: 2000/1000 MS (Java/Others)   ...

  10. git学习笔记05-从远程库克隆

    现在,假设我们从零开发,那么最好的方式是先创建远程库,然后,从远程库克隆. 首先,登陆GitHub,创建一个新的仓库,名字叫gitskills: 我们勾选Initialize this reposit ...