链接:
http://acm.timus.ru/problem.aspx?space=1&num=1010
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#problem/E
E - Discrete Function
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
Practice
URAL 1010
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.
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.
题意:
给出第一个数 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;
}