关于一些初级ACM竞赛题目的分析和题解(九)

一些逻辑题目,见下题:

A. Kefa and First Steps
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.

Help Kefa cope with this task!

Input

The first line contains integer n (1 ≤ n ≤ 105).

The second line contains n integers a1,  a2,  ...,  an (1 ≤ ai ≤ 109).

Output

Print a single integer — the length of the maximum non-decreasing subsegment of sequence a.

Examples
input
6
2 2 1 3 4 1

output
3

input
3
2 2 9

output
3

Note

In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.

In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.

Kefa决定在互联网上做一些钱,正好n天。 他知道在第i天(1≤i≤n),他赚了钱。 Kefa喜欢进步,这就是为什么他想知道序列ai中最大非递减子段的长度。 让我们提醒你,序列的子段是它的连续片段。 如果数字中的所有数字都是非递减的,则数字的一个子段称为非递减。

在第一个测试中,最大的非递减子段是从第三个到第五个的数字。
在第二个测试中,最大的非递减子段是从第一个到第三个的数字。

using namespace std;
typedef long long ll;
int a,b,c,n,s[100001];
int main()
{cin>>n;for (int i=0;i<n;i++){cin>>s[i];}for (int i=0;i<n;i++){if(s[i]>=s[i-1])a++;  //找到非递减序列else (b=max(a,b),a=1);}// 不断寻找最大非递减序列的长度b=max(a,b);printf("%d",b);}
A. Calculating Function
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

For a positive integer n let's define a function f:

f(n) =  - 1 + 2 - 3 + .. + ( - 1)nn

Your task is to calculate f(n) for a given integer n.

Input

The single line contains the positive integer n (1 ≤ n ≤ 1015).

Output

Print f(n) in a single line.

Examples
input
4

output
2

input
5

output
-3

Note

f(4) =  - 1 + 2 - 3 + 4 = 2

f(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3

知道题做的时候脑袋傻了,明明是高中知识我还给整的超时了,下面是代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,d,e,n;
int main()
{scanf("%lld",&n);if(n%2==0)printf("%lld",n/2);if(n%2!=0)printf("%lld",(-1-n)/2);}

是一个分奇偶的等差数列,分清题意就好了,

关于一些初级ACM竞赛题目的分析和题解(九)相关推荐

  1. 关于一些初级ACM竞赛题目的分析和题解(二)。

    关于一些初级ACM竞赛题目的分析和题解(二). 今天写了关于排序的题  中间有加号的复杂的一行字符   其次还有关于tolower函数的应用, 上题                           ...

  2. 关于一些初级ACM竞赛题目的分析和题解(十)

    关于一些初级ACM竞赛题目的分析和题解(十) 西面的题目是关于一些字母变换的,上题: A. Word time limit per test 2 seconds memory limit per te ...

  3. 关于一些初级ACM竞赛题目的分析和题解(六)。

    关于一些初级ACM竞赛题目的分析和题解(六). 下面是关于一些关于数字判断的题,比较简单,先来看第一题: A. Lucky Division time limit per test 2 seconds ...

  4. 2019浙江ACM省赛部分题解-ABDEFGHIJK

    太菜了,心态炸了.QAQ A-Vertices in the Pocket() 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

  5. 华东交通大学2018年ACM双基程序设计大赛题解

    华东交通大学2018年ACM"双基"程序设计竞赛 代码头多的都是标答Ctrl+c下来的,给自己挖个坟,回头有时间再填回去,不填回去就死在这里吧-- 传送门:https://ac.n ...

  6. ACM新生赛部分题解

    2021级的ACM新生赛已经完结了,我就自己做出来的八道题整理一下题解,因为其他是真的不会. 链接:登录-专业IT笔试面试备考平台_牛客网 来源:牛客网 一.我们是冠军 7 日星期 777 的凌晨,7 ...

  7. 2021暨南大学轩辕杯ACM程序设计新生赛题解

    title : 2021暨南大学轩辕杯ACM程序设计新生赛 date : 2021-12-12 tags : ACM,练习记录 author : Linno 题目链接:https://ac.nowco ...

  8. 2018年第十届ACM四川省省赛题解(10 / 11)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 2018ACM四川省省赛 题目链接:https://www.oj.swust.edu.cn/probl ...

  9. 华东交通大学2017年ACM双基程序设计大赛题解

    简单题 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submissio ...

  10. ACM程序设计基础(2)题解

    ACM水题二 CodeForces-1A Theatre Square[水题] - 海岛Blog - CSDN博客 AOJ0009 Prime Number[筛选法+前缀和] - 海岛Blog - C ...

最新文章

  1. 【基础】CSS实现多重边框的5种方式
  2. 设置树莓派的无线网卡为监听模式(monitor)
  3. 06-老马jQuery教程-jQuery高级
  4. zend studio让编译器导入项目为utf-8如何设置
  5. lamber表达式sql_lambda表达式转换sql
  6. Android之EditText自定义边框和边框颜色(转载)
  7. glibc的头文件 linux_求助,编译glibc头文件时出错
  8. Python 操作 MongoDB
  9. js jq 一些属性
  10. redis概念、做什么及其应用场景
  11. java中String类是什么_Java中字符串的学习(一)String类的概述及常见方法使用
  12. MIUI11新版本推送,小米10 Pro跑分轻松突破60万
  13. 微信支付服务器验证的java_Java中的微信支付(3):API V3对微信服务器响应进行签名验证...
  14. nginx相关概念——正向代理和反向代理
  15. Windows 10 IoT Core 17115 for Insider 版本更新
  16. FA:萤火虫算法的改进及Python实现
  17. 【备忘】传智播客黑马程序员28期JavaEE基础及就业班视频教程
  18. python中的IO操作
  19. Android 13 Beta 版发布,诸多亮点不容错过
  20. java异常之-Caused by: java.lang.IllegalStateException: Method has too many Body parameters

热门文章

  1. 主成分分析结果成分不显著_spss主成分分析结果解读
  2. 卡地亚计算机辅助设计,工程图纸电子版用什么软件看
  3. Abaqus DOC 搜索功能 在 IE浏览器 显示“应用程序已被JAVA安全阻止”解决办法
  4. FileNet入门学习
  5. php实现mkv视频播放,mkv怎么合并视频文件
  6. 目前最系统的程序员未来职业规划路线,请收藏
  7. layui里面layer弹窗渲染layerdate,时间控件不出现,闪现问题,F12才出来
  8. NAS安装迅雷远程下载
  9. 沃特玛采集均衡模块_采集均衡模块以及电池管理系统_2016212573884_说明书_专利查询_专利网_钻瓜专利网...
  10. 2022年低压电工考试及低压电工模拟考试题库