cf B. Jeff and Periods
2014-08-22 11:06
821 查看
http://codeforces.com/contest/352/problem/B
View Code
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int a[100010]; int n; bool vis[100010]; int len; struct node { int x,id; bool operator <(const node &a)const { return (x<a.x)||(x==a.x&&id<a.id); } } p[100010],p1[100010]; int main() { while(scanf("%d",&n)!=EOF) { memset(vis,0,sizeof(vis)); int cnt=0; for(int i=1; i<=n; i++) { scanf("%d",&a[i]); p[cnt].x=a[i]; p[cnt++].id=i; } sort(p,p+cnt); bool flag1=false; int cnt1=0; bool flag2=false; bool flag3=false; for(int i=0; i<cnt; i++) { if(!vis[p[i].x]) { if(!flag1) { flag1=true; } else { if(!flag2) { p1[cnt1].x=p[i-1].x; p1[cnt1++].id=len; } } flag2=false; flag3=false; len=0; vis[p[i].x]=true; } else { if(flag2)continue; if(!flag3) { len=p[i].id-p[i-1].id; flag3=true; } else { if(p[i].id-p[i-1].id!=len) { flag2=true; } } } } if(!flag2) { p1[cnt1].x=p[cnt-1].x; p1[cnt1++].id=len; } printf("%d\n",cnt1); for(int i=0; i<cnt1; i++) { printf("%d %d\n",p1[i].x,p1[i].id); } } return 0; }
View Code
相关文章推荐
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
- Codeforces Round #204 (Div. 2) B. Jeff and Periods
- CF_314D_Sereja and Periods
- Codeforces Round #204 (Div. 2) B - Jeff and Periods
- [CF 351B]Jeff and Furik[归并排序求逆序数]
- Codeforces 351D:Jeff and Removing Periods
- A. Jeff and Digits(cf)
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
- Codeforce - 352B - Jeff and Periods
- B. Jeff and Periods(cf)
- cf 204 div2 D. Jeff and Furik 逆序对
- CF 351D - Jeff and Removing Periods(离线 + 树状数组)
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
- [CF 351A]Jeff and Rounding[greedy]
- [CF 351B]Jeff and Furik[归并排序求逆序数]
- B. Jeff and Periods
- Jeff and Periods
- CF#204DIV2:B. Jeff and Periods
- codeforces-Jeff and Periods