BZOJ 1027 [JSOI2007]合金

2023-10-09 04:38
文章标签 bzoj 1027 jsoi2007 合金

本文主要是介绍BZOJ 1027 [JSOI2007]合金,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Description

  某公司加工一种由铁、铝、锡组成的合金。他们的工作很简单。首先进口一些铁铝锡合金原材料,不同种类的
原材料中铁铝锡的比重不同。然后,将每种原材料取出一定量,经过融解、混合,得到新的合金。新的合金的铁铝
锡比重为用户所需要的比重。 现在,用户给出了n种他们需要的合金,以及每种合金中铁铝锡的比重。公司希望能
够订购最少种类的原材料,并且使用这些原材料可以加工出用户需要的所有种类的合金。

Input

  第一行两个整数m和n(m, n ≤ 500),分别表示原材料种数和用户需要的合金种数。第2到m + 1行,每行三
个实数a, b, c(a, b, c ≥ 0 且 a + b + c = 1),分别表示铁铝锡在一种原材料中所占的比重。第m + 2到m +
 n + 1行,每行三个实数a, b, c(a, b, c ≥ 0 且 a + b + c = 1),分别表示铁铝锡在一种用户需要的合金中
所占的比重。

Output

  一个整数,表示最少需要的原材料种数。若无解,则输出–1。

Sample Input

10 10
0.1 0.2 0.7
0.2 0.3 0.5
0.3 0.4 0.3
0.4 0.5 0.1
0.5 0.1 0.4
0.6 0.2 0.2
0.7 0.3 0
0.8 0.1 0.1
0.9 0.1 0
1 0 0
0.1 0.2 0.7
0.2 0.3 0.5
0.3 0.4 0.3
0.4 0.5 0.1
0.5 0.1 0.4
0.6 0.2 0.2
0.7 0.3 0
0.8 0.1 0.1
0.9 0.1 0
1 0 0

Sample Output

5

HINT

Source

先用叉积求出那些点可能是凸包上的点,接着用floyd求最小环。


#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const double eps=1e-8;
int m,n,ans=1e9+7,f[505][505];
struct node
{double x,y;
}a[505],b[505];
double cross(double x1,double y1,double x2,double y2)
{return x1*y2-x2*y1;
}
double dot(double x1,double y1,double x2,double y2)
{return x1*x2+y1*y2;
}
bool check(int i,int j)
{for(int k=1;k<=n;k++){double x1=a[i].x-b[k].x,y1=a[i].y-b[k].y;double x2=a[j].x-b[k].x,y2=a[j].y-b[k].y;double t=cross(x1,y1,x2,y2);if(t>eps)return 0;if(t>-eps&&t<eps&&dot(x1,y1,x2,y2)>=eps)return 0;}return 1;
}
int main()
{scanf("%d%d",&m,&n);double t;for(int i=1;i<=m;i++)scanf("%lf%lf%lf",&a[i].x,&a[i].y,&t);for(int i=1;i<=n;i++)scanf("%lf%lf%lf",&b[i].x,&b[i].y,&t);memset(f,0x3f,sizeof(f));for(int i=1;i<=m;i++)for(int j=1;j<=m;j++)if(check(i,j))f[i][j]=1;for(int k=1;k<=m;k++)for(int i=1;i<=m;i++)for(int j=1;j<=m;j++)if(f[i][j]>f[i][k]+f[k][j])f[i][j]=f[i][k]+f[k][j];for(int i=1;i<=m;i++)ans=min(ans,f[i][i]);if(ans>1e9)printf("-1\n");elseprintf("%d\n",ans);return 0;
}


这篇关于BZOJ 1027 [JSOI2007]合金的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/170393

相关文章

JD 1027:欧拉回路

OJ题目:click here~~ 题目分析: 若图G中存在这样一条路径,使得它恰通过G中每条边一次,则称该路径为欧拉路径。若该路径是一个圈,则称为欧拉(Euler)回路。 具有欧拉路径的图称为欧拉图(简称E图)。 无向图存在欧拉回路的充要条件: 一个无向图存在欧拉回路,当且仅当该图拥有奇数度数的顶点的个数为0且该图是连通图。 有向图存在欧拉回路的充要条件: 一

【BZOJ】1324 Exca王者之剑 最大权独立集

传送门:【BZOJ】1324  Exca王者之剑 题目分析:赤裸裸的最大权独立集。。。最小割解决 代码如下: #include <cstdio>#include <vector>#include <cstring>#include <algorithm>using namespace std ;#define REP( i , a , b ) for ( int

【BZOJ】1026: [SCOI2009]windy数 数位DP

传送门:【BZOJ】1026: [SCOI2009]windy数 题目分析:数位DP水题。 代码如下: #include <stdio.h>#include <cstring>#include <algorithm>#define rep( i , a , b ) for ( int i = a ; i < b ; ++ i )#define For( i ,

【BZOJ】2152: 聪聪可可 点分治

传送门:【BZOJ】2152: 聪聪可可 题目分析:记录权值和%3的路径的个数。。。然后去重。。没了。。 代码如下: #include <vector>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std ;typedef lo

BZOJ 2440 2301 莫比乌斯应用

http://www.lydsy.com/JudgeOnline/problem.php?id=2440 Description 小 X 自幼就很喜欢数。但奇怪的是,他十分讨厌完全平方数。他觉得这些 数看起来很令人难受。由此,他也讨厌所有是完全平方数的正整数倍的数。然而 这丝毫不影响他对其他数的热爱。  这天是小X的生日,小 W 想送一个数给他作为生日礼物。当然他不能送一 个小X讨厌

BZOJ 3732: Network(最小生成树+倍增)

题目链接 题意:给出一个图,每个询问的格式是:A B,表示询问从A点走到B点的所有路径中,最长的边最小值是多少 很明显最终查询的边一定是在最小生成树里面的,先跑出最小生成树,然后,可以树链剖分,也可以使用倍增来计算 #include<bits/stdc++.h>using namespace std;#define cl(a,b) memset(a,b,sizeof(a))#define

BZOJ 2038 小Z的袜子(hose) (莫队离线)

题目地址:BZOJ 2038 裸的莫队算法。 代码如下: #include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>#in

BZOJ 2152 聪聪可可 (树上点分治)

题目地址:BZOJ 2152 找有多少对权值和为3的倍数的点。最简单的点分治。 代码如下: #include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#incl

BZOJ 3530 数数【AC自动机+数位dp】

[Sdoi2014]数数 简单数位dp+简单AC自动机 反正数位DP是队友写的 AC自动机要记录两个值,一个是是否为一个串的结束,即不合法状态,一个是前缀零的情况。 // whn6325689// Mr.Phoebe// http://blog.csdn.net/u013007900#include <algorithm>#include <iostr

BZOJ 3531 旅行【树链剖分】

[Sdoi2014] 简单的树链剖分 以每个信仰应该建一个线段树,空间复杂度为 O(5×1010) O(5\times 10^{10}) 因此会爆空间,所以需要动态申请空间。 // whn6325689// Mr.Phoebe// http://blog.csdn.net/u013007900#include <algorithm>#include <