spoj 297
就是对距离进行二分找最大值 ....
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std; int a[100010];
int n,C;
bool can(int lim)
{
int d = 0,w = 1;
for(int i = 1; i < C; i++)
{
while(a[w]-a[d] < lim && w < n)
w++;
if(w >= n)
return false;
d = w;
}
return true;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&C);
for(int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
sort(a, a+n);
int l = 1,r = a[n-1];
while(l +1 < r)
{
int mid = (l+r)/2;
if(can(mid))
l = mid;
else
r = mid;
}
printf("%d\n",l);
}
return 0;
}
spoj 297的更多相关文章
- BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5217 Solved: 1233 ...
- SPOJ DQUERY D-query(主席树)
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
- 【填坑向】spoj COT/bzoj2588 Count on a tree
这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...
- SPOJ bsubstr
题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...
- 【SPOJ 7258】Lexicographical Substring Search
http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...
- 【SPOJ 1812】Longest Common Substring II
http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...
- 【SPOJ 8222】Substrings
http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求 ...
- SPOJ GSS2 Can you answer these queries II
Time Limit: 1000MS Memory Limit: 1572864KB 64bit IO Format: %lld & %llu Description Being a ...
随机推荐
- get方法与post方法的使用
使用get方法获取页面的form内容 新建一个getform.html <html> <head> <title>Using Http Get Method< ...
- 如何查看eclipse或Myeclipse的版本号
对于eclipse 方法一: 在eclipse安装路径下用记事本打开 .eclipseproduct文件,里面就有eclipse版本号. 形如: name=Eclipse Platform id=or ...
- 实例介绍Cocos2d-x中Box2D物理引擎:碰撞检测
在Box2D中碰撞事件通过实现b2ContactListener类函数实现,b2ContactListener是Box2D提供的抽象类,它的抽象函数:virtual void BeginContact ...
- 学习之spring属性文件注入
package com.my.proper; import org.springframework.beans.factory.annotation.Value; import org.springf ...
- JQuery验证工具
一.写法一 var Validator = { // 邮箱isEmail : function(s) {var p = "^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z ...
- SecureCRT for Linux突破30天使用限制
当然还有一种方法,就是当你试用点i agree到时候,在~/.vandyke/Config 会生成一个文件SecureCRT_eval.lic,删除以后就可以恢复30天试用
- iOS 非ARC基本内存管理系列 -手把手教你ARC——iOS/Mac开发ARC入门和使用(转)
手把手教你ARC——iOS/Mac开发ARC入门和使用 Revolution of Objective-c 本文部分实例取自iOS 5 Toturail一书中关于ARC的教程和公开内容,仅用于技术交流 ...
- C# 导出 Excel
/// <summary> /// 导出Excel /// </summary> public void ExportExcel() { #region 添加引用 Micros ...
- Skyline中使用AxTE3DWindowEx打开新的一个球体
在winform窗体中拖入AxTE3DWindowEx控件. using system; using system.Collections.Generic; using System.Drawing; ...
- Js popup position which right under target item
<div style="margin-left:600px;"> <div id="Span1" style="color:#eee ...