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 ...
随机推荐
- Windows 删除 .svn标志
之前一个项目是在SVN下面管理的,后来,考出来了,然后在Eclispe中使用,后来想用SVN管理起来,但是项目中,还是有.svn标志,只能先删除了.svn文件,然后在用svn管理起来,后来,发现.sv ...
- 自定义Log模块
BuildConfig.DEBUG默认为true,在为app打上SignedKeyStore之后就为false, // Log控制器 MyLoger.openDebutLog(true); MyLog ...
- 谈谈我的编程之路---WAMP(三)
WAMP的一些配置与使用心得(APACHE)说实话,我感觉apache的配置真的还是蛮复杂的,感觉好像又在学一种语言,让我用比较庞大的概念来讲述这些东西,我也没办法做到就以实际应用出发出发,简单的说一 ...
- nginx 配一个简单的静态文件服务器 和一个虚似机
下面是个图片服务器: server { listen ; server_name img.xxx.xxx.com; root /data/site/img.xxx.xxx.com; access_lo ...
- C#的索引器
using System; using System.Collections; using System.Collections.Generic; using System.IO; namespace ...
- 无废话Android之activity的生命周期、activity的启动模式、activity横竖屏切换的生命周期、开启新的activity获取他的返回值、利用广播实现ip拨号、短信接收广播、短信监听器(6)
1.activity的生命周期 这七个方法定义了Activity的完整生命周期.实现这些方法可以帮助我们监视其中的三个嵌套生命周期循环: (1)Activity的完整生命周期 自第一次调用onCrea ...
- 无废话Android之内容观察者ContentObserver、获取和保存系统的联系人信息、网络图片查看器、网络html查看器、使用异步框架Android-Async-Http(4)
1.内容观察者ContentObserver 如果ContentProvider的访问者需要知道ContentProvider中的数据发生了变化,可以在ContentProvider 发生数据变化时调 ...
- C专家编程cdecl
理解所有分析过程的代码段 Page71(中文版) 你可以轻松地编写一个能够分析C语言的声明并把他们翻译成通俗语言的程序.事实上,为什么不?C语言声明的基本形式已经描述清楚.我们所需要的只是编写一段能够 ...
- VS2012 配置 OpenCV3.0
VS2012 配置 opencv3.0,相比之前的版本,3.0的配置简单了好多. 通过配置属性文件,可以做到一次配置,重复使用! 根据文章的操作在 win7 64bit VS2012 下成功配置 op ...
- 在网页中显示html代码
string str = "<div>aaa</div>"; this.Literal1.Text = string.Format("<pr ...