POJ 3618
来源:互联网 发布:程序员技术博客 编辑:程序博客网 时间:2024/06/05 12:01
一道关于绝对值排序的水题,学习一下方法。
题目链接:http://poj.org/problem?id=3618
#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<iostream>using namespace std;bool cmp (int a,int b){ return abs(a)<abs(b);}int weizhi[50010];int main(){ int n,a; long long t,sum; scanf("%lld%d",&t,&n); for(int i=0;i<n;i++) scanf("%d",&weizhi[i]); sort(weizhi,weizhi+n,cmp); sum=0;a=0;int c=0; for(int i=0;i<n;i++) { sum+=abs(weizhi[i]-a); c++; a=weizhi[i]; if(sum>t) break; } printf("%d\n",c-1); return 0;}
1 0
- POJ 3618
- POJ 3618 Exploration
- poj 3618 Exploration
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- matlab 矩阵数值比较总结
- 关于Request.Form的实验
- uboot中语句__asm__ __volatile__("": : :"memory");理解
- 借助WinDriver认识Windows PCIE设备的空间结构
- iOS 网络编程之TCP/IP <二> 框架的二次封装
- POJ 3618
- leetcode.304. Range Sum Query 2D - Immutable
- Codeforces Round #349 (Div. 2) C. Reberland Linguistics 【DP】
- dom4j回车换行符(给群中朋友需要解决的基础写的乱看看就行)
- iOS7.0导航栏设置
- stristr_strrchr.php
- java 资源获取
- 保存数据报错Write operations are not allowed in read-only mode (FlushMode.MANUAL)
- ApplicationInfo的flags属性