hdu 5834 四面体 观察+暴力
Magic boy Bi Luo with his excited tree
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 767 Accepted Submission(s): 201
You may attention that every V[i] can be taken only once, but for some C[i] , you may cost severial times.
Now, Bi Luo define ans[i] as the most value can Bi Luo gets if Bi Luo starts at node i.
Bi Luo is also an excited boy, now he wants to know every ans[i], can you help him?
Four each test:
The first line contain an integer N(N≤105).
The next line contains N integers V[i], which means the treasure’s value of node i(1≤V[i]≤104).
For the next N−1 lines, each contains three integers u,v,c , which means node u and node v are connected by an edge, it's cost is c(1≤c≤104).
You can assume that the sum of N will not exceed 106.
5
4 1 7 7 7
1 2 6
1 3 1
2 4 8
3 5 2
15
10
14
9
15
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
#define MM(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
using namespace std;
const int N=1e5+8; struct Point{
ll x,y,z,dis;
int id;
void read(){
scanf("%lld%lld%lld",&x,&y,&z);
}
bool operator<(const Point &a) const{
return this->dis<a.dis;
}
}p[205],v[205]; Point operator-(Point a,Point b)
{
return (Point){a.x-b.x,a.y-b.y,a.z-b.z};
} double dis(Point a)
{
return a.x*a.x+a.y*a.y+a.z*a.z;
} Point cross(Point a,Point b)
{
return (Point){a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x};
} double area(Point a,Point b,Point c)
{
return dis(cross(b-a,c-a));
} double dot(Point a,Point b)
{
return a.x*b.x+a.y*b.y+a.z*b.z;
} bool onface(Point a,Point b,Point c,Point d)
{
Point f=cross(a-b,c-b);
return dot(f,d-b)==0;
} int main()
{
int cas,n,kk=0,x,y;
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++) p[i].read();
ll ans6=0,ans45=0;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
{
ll len=dis(p[i]-p[j]);
int cnt=0;
for(int k=1;k<=n;k++)
if(k!=i&&k!=j)
{
if(dis(p[k]-p[i])-dis(p[k]-p[j])==0)
{
v[++cnt]=p[k];
v[cnt].dis=dis(p[k]-p[i]);
}
}
for(int k=1;k<=cnt;k++)
for(int w=k+1;w<=cnt;w++)
{
if((v[w].dis-v[k].dis)!=0) continue;
if(onface(p[i],p[j],v[k],v[w])) continue;
ll tmp=dis(v[w]-v[k]); if((tmp-len)==0&&(len-v[k].dis)==0) ans6++;
else ans45++;
}
}
ans45/=2;ans6/=6;
printf("Case #%d: %lld\n",++kk,ans45+ans6);
}
return 0;
}
分析:只想说两点:
1.两点连线的中垂线经过的整格点肯定是不多的,所以由此可以暴力。
2.T了话尝试去掉sqrt
hdu 5834 四面体 观察+暴力的更多相关文章
- hdu 5461 Largest Point 暴力
Largest Point Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- 【树形动规】HDU 5834 Magic boy Bi Luo with his excited tree
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5834 题目大意: 一棵N个点的有根树,每个节点有价值ci,每条树边有费用di,节点的值只能取一次,边 ...
- hdu 5762 Teacher Bo 暴力
Teacher Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5762 Description Teacher BoBo is a geogra ...
- HDU 5834 Magic boy Bi Luo with his excited tree(树形dp)
http://acm.hdu.edu.cn/showproblem.php?pid=5834 题意: 一棵树上每个节点有一个价值$Vi$,每个节点只能获得一次,每走一次一条边要花费$Ci$,问从各个节 ...
- HDU 1333 基础数论 暴力
定义一种数位simth数,该数的各位之和等于其所有质因子所有位数字之和,现给出n求大于n的最小该种数,n最大不超过8位,那么直接暴力就可以了. /** @Date : 2017-09-08 14:12 ...
- HDU 4618 Palindrome Sub-Array 暴力
Palindrome Sub-Array 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4618 Description A palindrome s ...
- HDU 2089 不要62 | 暴力(其实是个DP)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2089 题解: 暴力水过 #include<cstdio> #include<algor ...
- HDU 6115 Factory LCA,暴力
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6115 题意:中文题面 分析:直接维护LCA,然后暴力枚举集合维护答案即可. #include < ...
- HDU 5636 Shortest Path 暴力
Shortest Path 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5636 Description There is a path graph ...
随机推荐
- 【计数dp】Array Without Local Maximums
参考博客:[CF1068D]Array Without Local Maximums(计数DP) [题意] n<=1e5 dp[i][j][k]表示当前第i个数字为j,第i-1个数字与第i个之间 ...
- centos7 追加python3 + 使用pip + virtualenv
一.安装Python3的方法: 首先安装依赖包: yum -y groupinstall "Development tools" yum -y install zlib-devel ...
- java 异常捕捉 ( try catch finally ) 你真的掌握了吗?
掌握下面几条原则就可以完全解决“当try.catch.finally遭遇return”的问题. 原则:1.finally语句块中的代码是一定会执行的,而catch块中的代码只有发生异常时才会执行. 2 ...
- [C#.net]C#如何解析json文本文件
C#解析Json字符串,可以借助Newtonsoft.Json将Json字符串序列化为对象,再从对象中获取值 Newtonsoft.Json.JsonConvert.DeserializeObject ...
- Aveva Marine C# 二次开发入门001
1# 引用 C:\AVEVA\Marine\OH12.1.SP4\Aveva.ApplicationFramework.dll C:\AVEVA\Marine\OH12.1.SP4\Aveva.App ...
- golang(8):channel读写 & goroutine 通信
goroutine 1.进程和线程 A. 进程是程序在操作系统中的一次执行过程,系统进行资源分配和调度的一个独立单位 B. 线程是进程的一个执行实体,是CPU调度和分派的基本单位,它是比进程更小的能独 ...
- 小白学 Python 爬虫(25):爬取股票信息
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...
- wpf DrawingImage 奇葩问题
使用wpf drawingImage绘图是,会出现很奇怪的坐标问题,这个问题困扰很久 当在DrawingGroup中绘图的时候,坐标始终会从(0,0)开始无论设置多少值,奇怪一比 解决方法:首先在Dr ...
- 函数缓存 (Function caching)
函数返回值缓存是优化一个函数的常用手段.我们可以将函数.输入参数.返回值全部保存起来,当下次以同样的参数调用这个函数时,直接使用存储的结果作为返回(不需要重新计算). 函数缓存允许我们将一个函数对于给 ...
- python调用其他脚本
1.用python调用python脚本 #!/usr/local/bin/python3. import time import os count = str = ('python b.py') re ...