G-Extreme Sort (2015 German Collegiate Programming Contest (GCPC 15) + POI 10-T3)

John likes sorting algorithms very much. He has studied quicksort, merge sort, radix sort, and
many more.
A long time ago he has written a lock-free parallel string sorting program. It was a combination
of burstsort and multi-key quicksort. To implement burstsort you need to build a tree of buckets.
For each input string you walk through the tree and insert part of the string into the right bucket.
When a bucket fills up, it "bursts" and becomes a new subtree (with new buckets).
Figure G.1: Burstsort data structure
Well, enough about the past. Today John is playing with sorting algorithms again. This time it’s
numbers. He has an idea for a new algorithm, “extreme sort”. It’s extremely fast, performance
levels are OVER NINETHOUSAND. Before he tells anyone any details, he wants to make sure
that it works correctly.
Your task is to help him and verify that the so-called extreme property holds after the first phase
of the algorithm. The extreme property is defined as min (xi,j ) ≥ 0, where
xi,j =
{
aj − ai for 1 ≤ i < j ≤ N
9001 otherwise
Input
The first line contains a single integer N (1 ≤ N ≤ 1024). The second line contains N integers
a1 a2 . . . aN (1 ≤ ai ≤ 1024).
Output
Print one line of output containing “yes” if the extreme property holds for the given input, “no”
otherwise.
Sample Input 1 Sample Output 1
2
1 2
yes
Sample Input 2 Sample Output 2
4
2 1 3 4
no

思路:题意要求如果i<j并且aj-ai<0即为不符合要求,输出“no”;

        逐个读入数值,一旦当前ai小于前i-1个数的最大值即为不符合要求

AC代码:

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int main()
{
	int n;
	cin>>n;
	int maxx=0;
	bool f=0;
	while(n--)
	{
		int a;
		cin>>a;
		if(a<maxx)
			f=1;
		maxx=max(maxx,a);
	}
	if(f)
		puts("no");
	else
		puts("yes");
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Double.Qing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值