博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OUC_Summer Training_ DIV2_#2之解题策略 715
阅读量:4359 次
发布时间:2019-06-07

本文共 1846 字,大约阅读时间需要 6 分钟。

这是第一天的CF,是的,我拖到了现在。恩忽视掉这个细节,其实这一篇只有一道题,因为这次一共做了3道题,只对了一道就是这一道,还有一道理解了的就是第一篇博客丑数那道,还有一道因为英语实在太拙计理解错了题意,然后就没看了,现在更不想看了。再次感觉自己做题就是靠脑子,找规律。不像其他大牛一样一说解题思路,就是一套一套的算法。啊有时候听到头都晕了。。。好了言归正传吧。

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

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
3264
1 2

题意是:这儿有一个离散函数。它自变量的定义域为从1-N的整数(2〈=N〈=100000)。(每个给出的值一一对应1 to N的自变量) 每个函数值的类型均为LONGINT(C++中为signed long). 你需要去寻找函数图象上的2点,使其满足下列条件: 所有处于这2点之间的函数点是在连接这2点的直线的下方的,并且这条直线的倾角最大。输入第一行为一个数N。 然后下面N行是分别为对自变量取1-N时函数的值。输出仅一行,一对整数,即题目所求的2个点的横坐标,(也就是哪两个点,注意点的编号是从1开始的)并且第1个数必须小于第2个数。 如果有多解则只需输出第1个数最小的那对数。

分析:必然倾角最大的线段两端点相邻——如果有更好的点,为什么不靠的近些呢  所以 只要遍历一遍n-1个点就行了。

 

#include
int main(){ long long int a[100010]; long long int i,n,max = -1,m,t; scanf("%lld",&n); for(i = 0;i < n;i++) { scanf("%lld",&a[i]); } for(i = 0;i < n-1;i++) { m = a[i] - a[i+1]; if(m < 0)m = -m; if(max < m) { max = m; t = i; } } printf("%lld %lld\n",t+1,t+2);}
View Code

 

 

 

 

转载于:https://www.cnblogs.com/lwy-kitty/p/3207407.html

你可能感兴趣的文章
C++:文件的输入和输出
查看>>
Http协议、Tomcat、servlet
查看>>
Spring Boot (11) mybatis 关联映射
查看>>
macOS 下安装tomcat
查看>>
字符串格式化复习笔记
查看>>
jquery之ajax
查看>>
Pro Git(中文版)
查看>>
解决phpmyadmin-1800秒超时链接失效问题
查看>>
OpenGL第十一节:拉伸和过滤
查看>>
AlertDialog的onCreateDialog与onPrepareDialog用法
查看>>
swift菜鸟入门视频教程-12-21讲
查看>>
探偵ガリレオー転写る2
查看>>
快速排序算法C++实现[评注版]
查看>>
七尖记
查看>>
SAP(最短增广路算法) 最大流模板
查看>>
安装 OpenSSL 工具
查看>>
用长微博工具发布长微博
查看>>
大庆金桥帆软报表案例
查看>>
Proxy模式
查看>>
读书多些会怎样
查看>>