ural 1252. Sorting the Tombstones
1252. Sorting the Tombstones
Memory limit: 64 MB
Input
Output
Sample
| input | output |
|---|---|
5 |
1 |
Problem Source: Open collegiate programming contest for student teams, Ural State University, March 15, 2003
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int n, arr[N], order[N];
int ans; inline void Input()
{
scanf("%d", &n);
for(int i = ; i < n; i++) scanf("%d", &arr[i]);
} inline int Gcd(int a, int b)
{
if(b) return Gcd(b, a % b);
else return a;
} inline int Work(int *arr, int *order, int n)
{
int ret = ;
for(int i = ; i < n; i++)
{
int idx = lower_bound(order, order + n, arr[i]) - order;
int delta = abs(i - idx);
ret = Gcd(ret, delta);
}
return ret;
} inline void Solve()
{
ans = ;
for(int i = ; i < n; i++) order[i] = arr[i];
sort(order, order + n);
int t1 = Work(arr, order, n);
for(int i = ; i < n; i++) arr[i] = order[i] = - arr[i];
sort(order, order + n);
int t2 = Work(arr, order, n);
if(!t1 || !t2) ans = n;
else ans = max(t1, t2); printf("%d\n", ans - );
} int main()
{
freopen("a.in", "r", stdin);
Input();
Solve();
return ;
}
ural 1252. Sorting the Tombstones的更多相关文章
- URAL 1252 ——Sorting the Tombstones——————【gcd的应用】
Sorting the Tombstones Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
- URAL(timus) 1280 Topological Sorting(模拟)
Topological Sorting Time limit: 1.0 secondMemory limit: 64 MB Michael wants to win the world champio ...
- ural 1249. Ancient Necropolis
1249. Ancient Necropolis Time limit: 5.0 secondMemory limit: 4 MB Aerophotography data provide a bit ...
- URAL ——1249——————【想法题】
Ancient Necropolis Time Limit:5000MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u ...
- HDU Cow Sorting (树状数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1 ...
- 1306. Sorting Algorithm 2016 12 30
1306. Sorting Algorithm Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description One of the f ...
- 算法:POJ1007 DNA sorting
这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...
- U3D sorting layer, sort order, order in layer, layer深入辨析
1,layer是对游戏中所有物体的分类别划分,如UIlayer, waterlayer, 3DModelLayer, smallAssetsLayer, effectLayer等.将不同类的物体划分到 ...
- WebGrid with filtering, paging and sorting 【转】
WebGrid with filtering, paging and sorting by Jose M. Aguilar on April 24, 2012 in Web Development A ...
随机推荐
- 股票交易(洛谷U6084)
题目背景 kkk最近迷上了炒股. 题目描述 kkk炒了N天股,第i天的股价为a[i]元.kkk希望股票每天都上涨1元钱,但是操盘手lzn并不想让kkk赚很多钱导致他亏本,于是a[i]相对a[i-1]就 ...
- C++中实现对象的clone()
在C#中,许多对象自动实现了clone函数,在C++中,要拷贝一个对象,除了自定义一个拷贝构造函数来实现对象复制外,还可以像C#中那样实现一个clone函数,这需要借助编译器实现的一个隐藏拷贝构造函数 ...
- FragmentHelper
package com.icitymobile.anda.util; import java.lang.ref.SoftReference; import java.util.ArrayList; i ...
- [转]嵌入式SQC文件编译
Src Url:http://blog.csdn.net/cws1214/article/details/12996351 A.预编译部分 1.预编译DB2篇 1.1 什么是DB2预编译 在 ...
- NYOJ题目75日期计算
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAr4AAAInCAIAAADxjM2pAAAgAElEQVR4nO3dPVLjStsG4G8T5CyE2A
- Android之IPC机制
Android IPC简介 任何一个操作系统都需要有相应的IPC机制,Linux上可以通过命名通道.共享内存.信号量等来进行进程间通信.Android系统不仅可以使用了Binder机制来实现IPC,还 ...
- mySQL中如何给某一IP段的用户授权?
给一个用用户use ip: 192.168.0.1 语句是: grant all on *.* to root@192.168.0.1 identified by 'pass' 来授权 其中:root ...
- 有关Oracle数据库
创建数据库(DCA):http://jingyan.baidu.com/article/cbcede07cf42ef02f40b4dc2.html 创建表(连接数据库,sql创建数据表):http:/ ...
- 攻城狮在路上(壹) Hibernate(十一)--- 映射实体关联关系
本文以Customer和Address类的关系为例说明一对一关联映射:以Category和Item类的关系说明多对多关联关系.一.映射一对一关联: 分两种情况:按照外键映射和按照主键映射.这两种方式的 ...
- tornado使用(Mac)
安装需求 Tornado 在 Python 2.5, 2.6, 2.7 中都经过了测试.要使用 Tornado 的所有功能,你需要安装 PycURL (7.18.2 或更高版本) 以及 simplej ...