ACM程序设计选修课——1043: Radical loves integer sequences(YY)
1043: Radical loves integer sequences
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 36 Solved: 4
[Submit][Status][Web
Board]
Description
Input
The first line contains integer n (1 ≤ n ≤ 105).
The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 105).
The numbers are separated by spaces.
Output
exactly once in the sequence, px must equal 0).
Sample Input
1
3
4
9 9 3 5
Sample Output
1
3 0
3
3 0
5 0
9 1
这题前几次看真心没看懂,今天下午看了一下,发现是判断同一个数字出现的下标是否是等差数列,是则输出公差,否则则不输出。
没什么算法,就是记录时判断麻烦点..
代码:
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<cmath>
#include<queue>
#include<set>
#include<map>
bool ok[100009];
int mop[100009];
int step[100009];
int pos[100009];
using namespace std;
int main (void)
{
int t,i,j,n,tstep,cnt;
while (~scanf("%d",&n))
{
memset(ok,0,sizeof(ok));//判断改数是否存在等差数列
memset(mop,0,sizeof(mop));//记录该数的出现次数
memset(step,0,sizeof(step));//记录该数的公差
memset(pos,0,sizeof(pos));//记录该数的每(前)一次出现的下标pos
tstep=0;
cnt=0;
for (i=1; i<=n; i++)
{
scanf("%d",&t);
mop[t]++;
if(mop[t]>=1)//若出现过
{
if(mop[t]==1)//若此时只有一次
{
ok[t]=1;//暂时可行
cnt++;//暂时可行数+1
pos[t]=i;//此时为第一次出现的位置
step[t]=0;//此时公差为0
}
else if(mop[t]==2)//两次
{
step[t]=i-pos[t];//公差Δd
pos[t]=i;//位置更变
ok[t]=1;//暂时可行
}
else//三次以上
{
tstep=i-pos[t];//临时公差
if(tstep!=step[t])//若不等于此前的公差,则
{
if(ok[t])//若此前没有被减掉
cnt--;//减掉该数
ok[t]=0;//变为不可行
}
pos[t]=i;//位置变更
}
}
}
printf("%d\n",cnt);
for (i=1; i<=100000; i++)
{
if(ok[i])
{
if(mop[i]==1)
{
printf("%d %d\n",i,0);
}
else
{
printf("%d %d\n",i,step[i]);
}
}
}
}
return 0;
}
ACM程序设计选修课——1043: Radical loves integer sequences(YY)的更多相关文章
- ACM程序设计选修课——1018: Common Subsequence(DP)
问题 L: Common Subsequence 时间限制: 1 Sec 内存限制: 32 MB 提交: 70 解决: 40 [提交][状态][讨论版] 题目描述 A subsequence of ...
- ACM程序设计选修课——1057: Beautiful Garden(模拟+耐心调试)
1057: Beautiful Garden Time Limit: 5 Sec Memory Limit: 128 MB Submit: 25 Solved: 12 [Submit][Statu ...
- ACM程序设计选修课——1040: Alex and Asd fight for two pieces of cake(YY+GCD)
1040: Alex and Asd fight for two pieces of cake Time Limit: 1 Sec Memory Limit: 128 MB Submit: 27 ...
- ACM程序设计选修课——Problem E:(ds:图)公路村村通(Prim)
问题 E: (ds:图)公路村村通 时间限制: 1 Sec 内存限制: 128 MB 提交: 9 解决: 5 题目描述 现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本, ...
- ACM程序设计选修课——Problem F:(ds:图)旅游规划(优先队列+SPFA)
问题 F: (ds:图)旅游规划 时间限制: 1 Sec 内存限制: 128 MB 提交: 14 解决: 4 题目描述 有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路 ...
- ACM程序设计选修课——Problem E:(ds:图)公路村村通(优先队列或sort+克鲁斯卡尔+并查集优化)
畅通工程 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- ACM程序设计选修课——Problem D: (ds:树)合并果子(最优二叉树赫夫曼算法)
Problem D: (ds:树)合并果子 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 80 Solved: 4 [Submit][Status][ ...
- ACM程序设计选修课——1076汇编语言(重定向+模拟)
1076: 汇编语言 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 34 Solved: 4 [Submit][Status][Web Board] ...
- ACM程序设计选修课——1065: Operations on Grids(暴力字符串)
1065: Operations on Grids Time Limit: 3 Sec Memory Limit: 128 MB Submit: 17 Solved: 4 [Submit][Sta ...
随机推荐
- 如何将SAP Multi Target应用部署到SAP云平台的Cloud Foundry环境去
SHINA是SAP HANA Interactive Education的缩写,是一个demo应用,用于演示如何开发SAP HANA原生应用. 这个应用包含了sample数据以及HANA数据库表,vi ...
- CF Gym 100637G \#TheDress (水)
题解:读懂题意按照题意模拟... 熟悉了一个库函数,strstr,memcpy #include<cstdio> #include<cstring> int main() { ...
- docker-企业级镜像仓库harbor
Habor是由VMWare公司开源的容器镜像仓库.事实上,Habor是在Docker Registry上进行了相应的企业级扩展,从而获得了更加广泛的应用,这些新的企业级特性包括:管理用户界面,基于角色 ...
- x86,x64,i386,i686
x64其实就是64位, x86其实就是32位. 1. i386 适用于intel和AMD所有32位的cpu.以及via采用X86架构的32的cpu. intel平台包括8086,80286,80386 ...
- Element表单验证(2)
Element表单验证(2) 上篇讲的是async-validator的基本要素,那么,如何使用到Element中以及怎样优雅地使用,就在本篇. 上篇讲到async-validator由3大部分组成 ...
- DNA Pairing-freecodecamp算法题目
DNA Pairing 1.要求 DNA 链缺少配对的碱基.依据每一个碱基,为其找到配对的碱基,然后将结果作为第二个数组返回. Base pairs(碱基对)是一对 AT 和 CG,为给定的字母匹配缺 ...
- Mac配置gdb的一些问题
1.Unable to find Mach task port for process-id 1527: (os/kern) failure (0x5). (please check gdb is ...
- 【dp】饥饿的牛
普通dp题 题目描述 牛在饲料槽前排好了队.饲料槽依次用1到n(1 ≤ n ≤ 2000)编号.每天晚上,一头幸运的牛根据约翰的规则,吃其中一些槽里的饲料. 约翰提供b个区间的清单.一个区间是一对整数 ...
- [51Nod] 1218 最长递增子序列 V2
如何判断一个元素是否一定在LIS中?设f[i]为以ai结尾的LIS长度,g[i]为以ai开头的LIS长度,若f[i]+g[i]-1==总LIS,那么i就一定在LIS中出现 显然只出现一次的元素一定是必 ...
- python3.7 内置函数整理
#!/usr/bin/env python __author__ = "lrtao2010" #python3.7 内置函数整理 #abs(x) #返回数字的绝对值. 参数可以是整 ...