链接:



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. ansible自动化工具使用

    1.服务端配置 安装即可,无需启动,在安装ansible之前需要配置epel源 [root@m01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirr ...

  2. [Algorithms] Using Dynamic Programming to Solve longest common subsequence problem

    Let's say we have two strings: str1 = 'ACDEB' str2 = 'AEBC' We need to find the longest common subse ...

  3. UVa 156 Ananagrams(STL,map)

     Ananagrams  Most crossword puzzle fans are used to anagrams--groups of words with the same letters ...

  4. 系统封装 如何为原生PE集成软件

    1 我们首先集成Explorer.老外的BSExplorer比较好用,下载之后得到这些文件,不算太大.   2 这里需要注意,前一章讲解如何打造原生PE已经制作成了ISO,这里想要集成软件还需要回到刚 ...

  5. pugixml 的常见读写操作

    pugixml github地址 : https://github.com/zeux/pugixml pugixml 可以在github上直接下载到源码,包括两个头文件(pugixml.hpp  pu ...

  6. Android学习(十) SQLite 基于SQLiteOpenHelper的操作方式

    main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...

  7. Oracle基础(二) 创建数据库实例

    Oracle中数据库也称为数据库实例,在Oracle在安装过程中可以选择创建数据库,也可以再安装之后再进行创建. 一般创建数据库可以使用图形界面方式和SQL指令的方式,由于SQL指令方式较为复杂,这里 ...

  8. java代理ip有效检测

    java实现代理ip有效检测,依赖Apache的HttpClient   正式版:       /**        * 批量代理IP有效检测        *        * @param pro ...

  9. c++打印蛇形矩阵

    一个m*n的矩阵里按照下图形式填充,最后形成的矩阵即为蛇形矩阵,下图是m=4, n =5时的蛇形矩阵: 方法一:逐层循环 #include <iostream> using namespa ...

  10. atom无法安装插件的解决方法

    atom通过setting中无法下载插件,通过apm也无法下载插件,可能是网络.config配置的问题,不好解决. 下面的方法全手动,基本属于万金油方法: 1,在atom的setting页面中点击op ...