链接:



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. Timeline简单配置

    Timeline是一个Jquery时间轴插件.效果如图 获取地址:https://github.com/ka215/jquery.timeline 配置 (1)html表头加入 <link re ...

  2. Hadoop部署记录

    1.准备Linux环境 1.0先将虚拟机的网络模式选为NAT 1.1修改主机名 vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=node1 ### ...

  3. 2017.3.31 spring mvc教程(七)多视图控制器

    学习的博客:http://elf8848.iteye.com/blog/875830/ 我项目中所用的版本:4.2.0.博客的时间比较早,11年的,学习的是Spring3 MVC.不知道版本上有没有变 ...

  4. 一起学Netty(一)之 Hello Netty

    一起学Netty(一)之 Hello Netty 学习了:https://blog.csdn.net/linuu/article/details/51306480

  5. Linq 数据排序,分页

    在用Linq查询中,常常需要用到分页功能,因为每次都需要些分页这些功能,于是把分页功能提取出来,不喜大家勿喷,只是贴出来,自觉地很实用.一下贴出核心代码: /// <summary> // ...

  6. [Apollo Server] Get started with Apollo Server

    Get started with apollo server with node.js: Install: npm install --save apollo-server graphql index ...

  7. FizzBuzz and Fibonacci优化

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  8. EffectiveJava(3)使用是由构造器或枚举类型强化singleton

    使用是由构造器或枚举类型强化singleton 普通singleton:借助AccessibleObject.setAssess方法,通过反射机制调用私有构造器.抵御这种攻击可以修改构造器,让其再被要 ...

  9. 模式识别:利用MATLAB生成模式类

    近期開始了模式识别的学习,在此之前须要对模式和模式类的概念有一个了解,这里使用MATLAB实现一些模式类的生成.在此之前,引用百科上对于模式识别和模式类的定义.也算加深以下了解: 模式识别(Patte ...

  10. Directional Light,Ambient,Specular,光照感性认识...