codeforces An express train to reveries 814B
来源:互联网 发布:php正则表达式 编辑:程序博客网 时间:2024/05/29 05:07
题目链接:
http://codeforces.com/contest/814/problem/B
题意:
找到一串数字,它跟A,B串(互相)只有一个不同。
题解:
通过贪心的思想可以知道,如果要满足条件,那么就只会出现两种情况,要么一个不同,要么两个不同。
得到这个以后就简单很多了,直接进行暴力就行了。
代码:
#include <cmath>#include <cstdio>#include <map>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define met(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3fconst int maxn = 1000+10;map<int,int> mp;int num1[maxn];int num2[maxn];int num[maxn];int pos[maxn];int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&num1[i]); for(int i=0;i<n;i++) scanf("%d",&num2[i]); mp.clear(); int len=0; met(pos,0); for(int i=0;i<n;i++) { if(num1[i]!=num2[i]) pos[len++]=i; else mp[num1[i]]=1; } met(num,0); for(int i=0;i<n;i++) num[i]=num1[i]; if(len==1) { int x=pos[0]; for(int i=1;i<=n;i++) { if(mp[i]==0) { num[x]=i; break; } } } else { int x=pos[0]; int y=pos[1]; num[x]=num1[x]; num[y]=num2[y]; mp.clear(); for(int i=0;i<n;i++) { mp[num[i]]++; if(mp[num[i]]>=2) { num[x]=num2[x]; num[y]=num1[y]; break ; } } } for(int i=0;i<n;i++) { if(i!=n-1) printf("%d ",num[i]); else printf("%d\n",num[i]); }}
阅读全文
0 0
- codeforces B. An express train to reveries
- 【Codeforces 814 B. An express train to reveries】+ 构造
- codeforces 814B An express train to reveries
- codeforces 814B An express train to reveries
- codeforces 814B An express train to reveries(思维)
- Codeforces 814B-An express train to reveries
- Codeforces 814 B An express train to reveries
- codeforces 814 B An express train to reveries
- CodeForces 814B An express train to reveries
- codeforces An express train to reveries 814B
- CodeForces-814B An express train to reveries 解题报告
- 814/ B. An express train to reveries
- Codeforces Round #418 B--An express train to reveries
- An express train to reveries CodeForces
- B. An express train to reveries
- An express train to reveries
- An express train to reveries
- An express train to reveries
- Azure虚拟机批量设置静态IP
- 已有打开的与此 Command 相关联的 DataReader,必须首先将它关闭
- mysql——数据库事务(C#代码)
- MVC开发Entity更新数据库错误
- asp.net Mvc 访问静态页面
- codeforces An express train to reveries 814B
- 【转】C#中调用python脚本
- 重装powershell出现错误
- Android 仿微博@ # 艾特 话题功能
- 使用Asp.net 接收html提交的表单
- MVC View面页提交表单时,面页接收不到值时
- Mvc--Html.ActionLink()用法
- USB参考资料
- ASP.NET MVC view与controller传值方式