CodeForces Educational #24 D Solution
来源:互联网 发布:vevo lazr软件下载 编辑:程序博客网 时间:2024/06/05 05:01
题意:给出一串序列(1e5个),每个数字介于1-1e6之间,给定一个A,要求:找到一个B,使得对于每个位置i:B的累计出现次数严格大于A的累计出现次数
题解:这个题属于预处理技巧。每次读入一个data,如果cnt[data]合法,即cnt[data]>cnt[A],那么把cnt继续++,否则,cnt[data]停止更新。然后读入所有数据之后,遍历寻找cnt比cnt[A]大的,就是答案。
Code:
#include<bits/stdc++.h>using namespace std;#define MAXN 105bool use [MAXN];int ans [MAXN];int m,n;int main(){ int now; cin>>n>>m; cin>>now; for (int i=1;i<m;i++){ int temp; cin>>temp; int a = temp - now; if (a<=0){ a+=n; } if (ans[now]==0&&use[a]||ans[now]!=0&&ans[now]!=a){ cout<<"-1"<<endl; return 0; } use[a]=true; ans[now]=a; now= temp; } int as=1; for (int i=1;i<=n;i++){ if(ans[i]==0){ while(use[as])as++; cout<<as<<" "; as++; }else cout<<ans[i]<<" "; } return 0;}
阅读全文
0 0
- CodeForces Educational #24 D Solution
- Educational Codeforces Round 21-D
- Educational Codeforces Round 5 D
- Educational Codeforces Round 26 D
- Educational Codeforces Round 24 D. Multicolored Cars 补题
- 解题报告:Educational Codeforces Round 24 D,E,F
- Educational Codeforces Round 24
- Educational Codeforces Round 24
- Educational Codeforces Round 24
- Codeforces Educational Round 2 D题
- educational codeforces round8 D 数位dp
- Educational Codeforces Round 10 D. Nested Segments
- Educational Codeforces Round 10 D Nested Segments
- Educational Codeforces Round 10 D.Nested Segments
- Educational Codeforces Round 12 D. Simple Subset
- Educational Codeforces Round 12 D. Simple Subset
- Educational Codeforces Round 15 D 数学推导
- Educational Codeforces Round 11 D 计算几何
- 【二叉树】层次遍历
- 4----编程判断是某年的第几天
- Java基础知识(不定期更新)
- Java基础2
- ubuntu中管理用户和用户组
- CodeForces Educational #24 D Solution
- JVM 堆、栈、常量池、对象创建(摘抄书上的内容,当做笔记吧)
- git杂记
- 正则表达式表单验证实例
- 虚拟币开发专题(数字货币怎样从POW挖矿迁移到POS利息)
- pip 从本地文件夹安装
- 小白学习贴: C# TCP服务器
- json数据格式
- OSG渲染状态管理