链接:



E - Discrete Function

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

There is a discrete function. It is specified for integer arguments from 1 to N (2 ≤ N ≤ 100000). Each value of the function is longint (signed long in C++). You have to find such two points of the function
for which all points between them are below than straight line connecting them and inclination of this straight line is the largest.

Input

There is an N in the first line. Than N lines follow with the values of the function for the arguments 1, 2, …, N respectively.

Output

A pair of integers, which are abscissas of the desired points, should be written into one line of output. The first number must be less then the second one. If it is any ambiguity your program should write the pair with the smallest
first number.

Sample Input

input output
3
2
6
4
1 2

题意:

给出第一个数 N 表示有 N 个点
下面 N 行 每行一个数, 可以看成是纵坐标的值.比如说第一个数 a1, 代表坐标(1,a1)
要你找出两个点,要求两点之间的所有点【for which all points between them
are below than straight line 这里比较坑,读题时一般会忽略,然后就蒙了】都在这两点连线的下面。然后输出这两点的横坐标就好了。(也就是第几个点)
注意:输出时保证第一个点的横坐标小于第二个点的横坐标。

算法:

暴力求解
先上一张群里看到的图片

思路:

就是找相邻的两点,输出差值最大的相邻两点的下标就好了Orz...一道没有什么意义的题.
PS:开始没有想清楚为什么一定是相邻的两点,直接忽略了 between them就以为是求所有点中斜率绝对值最大的那两个了。

证明:

KB大神给我上的图:

如果不是相邻的 两个点,那么所求的斜率必定不是最大的,比如说上图圆中的那条线
╮(╯▽╰)╭都是between them 惹的祸,这样一来,题目就水了.

注意:输入的数是超 int 的了。

code:

Accepted 112 KB 46 ms Visual C++ 2010 563 B

习惯用__int64了。。。改成 double 也可以过

#include<stdio.h>
int main()
{
int n;
__int64 a,b,c;
int x1,x2;
while(scanf("%d", &n) != EOF)
{
__int64 Max = 0, ans;
x1 = 1; x2 = 2;
scanf("%I64d", &a);
for(int i = 2; i <= n; i++)
{
scanf("%I64d", &b);
ans = b-a;
ans = ans >= 0 ? ans : -ans; if(ans > Max)
{
Max = ans;
x1 = i-1;
x2 = i;
}
a = b; //存
}
printf("%d %d\n", x1,x2);
}
return 0;
}






URAL 1010 Discrete Function【简单暴力】的更多相关文章

  1. Ural 1010. Discrete Function

    1010. Discrete Function Time limit: 1.0 secondMemory limit: 64 MB There is a discrete function. It i ...

  2. Discrete Function(简单数学题)

    Discrete Function There is a discrete function. It is specified for integer arguments from 1 to N (2 ...

  3. 经典游戏--24点--c++代码实现和总体思路(简单暴力向)

    24点 24点是一个非常经典的游戏,从扑克牌里抽4张牌,其中J=11,Q=12,K=13,然后经过+,-,*,/,(),的计算后,使得计算得值为24,例如抽到1,2,2,5四张牌,那么 (1+5)*( ...

  4. fragment+viepager 的简单暴力的切换方式

    这里是自定义了一个方法来获取viewpager private static ViewPager viewPager; public static ViewPager getMyViewPager() ...

  5. 管道函数(pipelined function)简单使用示例

    -----------------------------Cryking原创------------------------------ -----------------------转载请注明出处, ...

  6. HDU 4705 Y (2013多校10,1010题,简单树形DP)

    Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...

  7. URAL 1203 Scientific Conference 简单dp 难度:0

    http://acm.timus.ru/problem.aspx?space=1&num=1203 按照结束时间为主,开始时间为辅排序,那么对于任意结束时间t,在此之前结束的任务都已经被处理, ...

  8. UVaLive 7457 Discrete Logarithm Problem (暴力)

    题意:求一个x使得 a^x%p = b p为素数: 析:从1开始扫一下就好,扫到p-1就可以了,关键是这个题为什么要用文件尾结束,明明说是0,但是不写就WA... 代码如下: #pragma comm ...

  9. URAL 1326. Bottle Taps(简单的状压dp)

    题目不太好读懂,就是先给你一个n代表要从n个物品中买东西,然后告诉你这n个东西的单位价格,在给你m个集合的情况.就是每一个结合中有x件物品.他们合起来买的价格是k.这x件物品依次是:p1--px.之后 ...

随机推荐

  1. MySQL的id生成策略

    1 自增 CREATE TABLE `test` ( `id` ) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAUL ...

  2. Redis缓存清理

    Redis缓存清理 学习了:https://www.cnblogs.com/ZnCl/p/7116870.html 使用 redis-cli.exe登录, 使用flushall 命令: 或者key * ...

  3. [Other] An Overview of Arrays and Memory

    One integer takes 32bit in memory, 1 byte = 8bits, therefore one integer takes 4 bytes. Now let's as ...

  4. selenium 的页面对象模型Page Object

    页面对象模型page object model是selenium中的一种脚本设计模式,它能将页面元素封装起来,与业务操作分隔开, 在页面变化改变时,无需去修改业务逻辑代码,提高脚本维护的效率. 1.p ...

  5. node - 上传文件并且修改名称

    html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  6. 【转载】json对象的使用

    使用JSON 进行数据传输 一.选择的意义 在异步应用程序中发送和接收信息时,可以选择以纯文本和 XML 作为数据格式.为了更好的使用ajax, 我们将学习一种有用的数据格式 JavaScript O ...

  7. SecureCRT如何调整好看的黄色

    1.常规 →默认会话→编辑默认编辑→白黑 字体为console 2.全局选项 ANSI颜色有一个 把黄色 拖过去即可

  8. Mysql5.6压缩包安装到windows&& 卸载命令

    1.根目录下有一个my-default.ini,复制一下,重命名为my.ini,然后改一下my.ini为符合你情况的配置,一般只需要改basedir .datadir .port ,注意前边的井号去掉 ...

  9. JQuery DataTables学习

    1.Datatables简单介绍 DataTables是一个jQuery的表格插件.这是一个高度灵活的工具,根据的基础逐步增强,这将添加先进的互动控制.支持不论什么HTML表格. 主要特点: 自己主动 ...

  10. Jmeter3.0-多维度的图形化HTML报告

    本文转载于推酷:http://www.tuicool.com/articles/BNvuEzr 在JMeter3.0之前,官方只提供在工具的UI上对测试结果部分维度的图形化展示,这对我带来了两方面的困 ...