【bzoj1027】合金
【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】合金的更多相关文章
- bzoj1027【JSOI2007】合金
题目描述 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的合金.新的合金 ...
- bzoj1027 [JSOI2007]合金
1027: [JSOI2007]合金 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 2671 Solved: 703[Submit][Status][ ...
- bzoj千题计划123:bzoj1027: [JSOI2007]合金
http://www.lydsy.com/JudgeOnline/problem.php?id=1027 因为x+y+z=1,所以z=1-x-y 第三维可以忽略 将x,y 看做 平面上的点 简化问题: ...
- BZOJ1027 [JSOI2007]合金 【计算几何 + floyd】
题目 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的 原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的合金.新的合金的 ...
- [bzoj 1027][JSOI2007]合金(解析几何+最小环)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1027 分析: 首先因为一个合金的和为1,所以考虑2个材料合金能否合成一个需求合金的时候 ...
- 合金装备V 幻痛 制作技术特辑
合金装备V:幻痛 制作特辑 资料原文出自日版CGWORLD2015年10月号 在[合金装备4(Metal Gear Solid IV)]7年后,序章作品[合金装备5 :原爆点 (Metal Gea ...
- 【BZOJ】【1027】【JSOI2007】合金
计算几何/凸包/Floyd Orz rausen大爷太强辣 计算几何题目果然不会做>_> 这个题……虽然他给了3个坐标,但实际上是个二维的计算几何题= =因为第三维坐标可以直接用前两维坐标 ...
- 1027: [JSOI2007]合金 - BZOJ
Description 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的 ...
- BZOJ_1027_[JSOI2007]_合金_(计算几何+Floyd求最小环)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1027 共三种金属,\(m\)种材料,给出每种材料中三种金属的占比. 给出\(n\)种合金的三种 ...
随机推荐
- Struts2的异常处理
Struts2的异常处理 1.异常处理机制(1)发送请求到控制器(Action); (2)Action出现异常后,依照所捕捉的不同异常转入不同的视图资源. 2.异常捕捉 (1)在Action的处理逻辑 ...
- merge into的用法
merge into 是英文的一个短语,意思是汇入,合并.顾名思义,merge into是合并了insert和update操作,其执行效率要高于分别单独执行insert和update语句. //创建表 ...
- 【leetcode❤python】 38. Count and Say
#-*- coding: UTF-8 -*- class Solution(object): def countAndSay(self, n): """ ...
- UVA 437 十九 The Tower of Babylon
The Tower of Babylon Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Subm ...
- Python操作文件、文件夹、字符串
Python 字符串操作 去空格及特殊符号 s.strip().lstrip().rstrip(',') 复制字符串 #strcpy(sStr1,sStr2) sStr1 = 'strcpy' sSt ...
- ASP.NET API盘点
1.控制只返回JSON一种数据 public class JsonContentNegotiator : IContentNegotiator { private readonly JsonMedia ...
- CSS的单位及css3的calc()及line-height百分比
锚点:css中百分比减去固定元素 单位介绍 说到css的单位,大家应该首先想到的是px,也就是像素,我们在网页布局中一般都是用px,但是近年来自适应网页布局越来越多,em和百分比也经常用到了.然后随着 ...
- 一个关于echo的小知识点
一个关于echo的小知识点 echo一个布尔值时,如果是true,输出1,而如果是false,将什么都不输出! 网上搜的一个解释: 对于数字类型来说,false 确实 是 0, 而对strin ...
- [HDOJ5935]Car(精度,数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5935 题意:有个老司机在开车, 开车过程中车的速度是不减的. 交警记录了这个老司机在nn个时间点的位置 ...
- sencha touch建立新项目
首先你得有一个sencha touch的环境,如下图: 图1 touch的sdk环境 有了这个之后,通过在cmd中执行下列命令: sencha -sdk /path/to/framework gene ...