【HDOJ6343】Graph Theory Homework(贪心)
题意:
给定n个点,每个点有权值a[i],从A走到B的花费是下取整sqrt(a[i]-a[j]),求从1号点走到n号点的最小花费
1<=n,a[i]<=1e5
思路:

#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair const int N=;
int a[N],n,cas;
int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} int main()
{
// freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
scanf("%d",&cas);
for(int i=;i<=cas;i++)
{
scanf("%d",&n);
for(int j=;j<=n;j++) scanf("%d",&a[j]);
int t=sqrt(abs(a[n]-a[]));
printf("%d\n",t);
}
return ;
}
【HDOJ6343】Graph Theory Homework(贪心)的更多相关文章
- 2018 Multi-University Training Contest 4 Problem L. Graph Theory Homework 【YY】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Problem L. Graph Theory Homework Time Limit: 2000 ...
- HDU 6343 - Problem L. Graph Theory Homework - [(伪装成图论题的)简单数学题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6343 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- HDU 6343.Problem L. Graph Theory Homework-数学 (2018 Multi-University Training Contest 4 1012)
6343.Problem L. Graph Theory Homework 官方题解: 一篇写的很好的博客: HDU 6343 - Problem L. Graph Theory Homework - ...
- Introduction to graph theory 图论/脑网络基础
Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...
- The Beginning of the Graph Theory
The Beginning of the Graph Theory 是的,这不是一道题.最近数论刷的实在是太多了,我要开始我的图论与树的假期生活了. 祝愿我吧??!ShuraK...... poj18 ...
- Codeforces 1109D Sasha and Interesting Fact from Graph Theory (看题解) 组合数学
Sasha and Interesting Fact from Graph Theory n 个 点形成 m 个有标号森林的方案数为 F(n, m) = m * n ^ {n - 1 - m} 然后就 ...
- CF1109D Sasha and Interesting Fact from Graph Theory
CF1109D Sasha and Interesting Fact from Graph Theory 这个 \(D\) 题比赛切掉的人基本上是 \(C\) 题的 \(5,6\) 倍...果然数学计 ...
- HDU6029 Graph Theory 2017-05-07 19:04 40人阅读 评论(0) 收藏
Graph Theory Time Limit: 2000/1000 M ...
- Codeforces 1109D. Sasha and Interesting Fact from Graph Theory
Codeforces 1109D. Sasha and Interesting Fact from Graph Theory 解题思路: 这题我根本不会做,是周指导带飞我. 首先对于当前已经有 \(m ...
随机推荐
- Java GUI简介
Java有2个GUI库:AWT.Swing. AWT是SUN最早提供的GUI库,依赖本地平台,界面不好看,功能有限.之后推出了Swing,Swing并没有完全替代AWT,而是建立在AWT基础上的.Sw ...
- java实现单向链表的增、删、改、查
单向链表 作者:vashon package com.ywx.link; /** * 单向链表 * @author vashon * */ public class LinkTest { public ...
- git 初识
现在平时用的都是SVN,感觉还是挺好用的.就是有的时候解决冲突的时候有点麻烦.但这样也是不可避免的. 今天看来下GIT,同样是版本控制,GIT的原理,和SVN还是不一样的.我个人的理解,SVN是对每个 ...
- COGS 2274. [HEOI 2016] tree
★☆ 输入文件:heoi2016_tree.in 输出文件:heoi2016_tree.out 简单对比时间限制:1 s 内存限制:128 MB 这道题数据弱到炸了 . 第一次做用树刨 ...
- Docker Hello World容器运行报错的解决办法
费了好大力气从Docker官网下载了Docker Community Editor的安装镜像,Docker.dmg, 总共将近500MB,双击进行安装: 命令行里使用docker version查看版 ...
- Cocos工程命名规则整理(node部分)
CocosCreator工程内的命名工程节点的命名规则工程内节点是程序调用资源的主要凭证,一套统一的命名方式和结构可以很大程度降低程序使用Cocos工程的难度 CocosCreator工程是由node ...
- System类与两种输入流
1.System类对I/O的支持系统输出System.out.println 是利用了I/O流的模式完成的.实际是打印流PrintStream对象 System类中定义了三个操作的常量 1.标准/系统 ...
- Comparator.comparing比较排序
使用外部比较器Comparator进行排序 当我们需要对集合的元素进行排序的时候,可以使用java.util.Comparator 创建一个比较器来进行排序.Comparator接口同样也是一个函数式 ...
- jquery--cookie应用
示例:发送手机验证码 防止页面刷新后,发送验证码按钮重置 注:橙色部分为后增加代码,为防止验证码等待期间用户退出或者切换到其他页面以至于很久之后回到当前页面倒计时还在的问题,加入时间对比,记录用户发送 ...
- gocode安装不上的解决办法
mkdir -p $GOPATH/src/golang.org/x //路径下创建此文件 cd $GOPATH/src/golang.org/x //切换到此目录 git clone ht ...