【HDOJ6343】Graph Theory Homework(贪心)
2024-09-04 09:11:29
题意:
给定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 ;
}
最新文章
- Hadoop的核心组件和生态圈
- PHP Warning: PHP Startup: in Unknown on line 0
- JAVA学习博客---2015-8
- Java:集合for高级循环遍历
- Linux 挂载iso,并设置为源
- 动态可视化库Vis.js:社交关系谱
- window.location.href 和 document.location.href
- python3 第二章 - 第一个程序
- Zookeeper分布式服务协调组件
- 安卓手机USB共享网络给PC上网
- mpvue-Vant Weapp踩坑记
- 图片懒加载、selenium和PhantomJS
- php(curl请求)测试接口案例
- Oracle列转行函数LISTAGG()
- 关于不执行整个大项目而是执行其中一部分独立文件夹的时候的python运行方法
- javascript 面向过程和面向对象
- CSS: Position Introduction.
- openstack项目【day23】:虚拟化介绍
- lua lua_settable
- CentOS 安装Sqlite3