796B
来源:互联网 发布:excel表格怎么数据统计 编辑:程序博客网 时间:2024/06/06 12:30
题意:有n个杯子分布在x正方向上,第i个杯子的坐标为(i,0)。 已知有m个点,当杯子中的骨头正好在这些点的时候就结束。共执行 k次 操作,每次操作讲i,j两个杯子内的内容互换~~~~问最后骨头会在哪个坐标下落(起初在杯子1中,即(1,0))。
思路:模拟啊模拟
复杂度分析:O(n) 级别
错误思路: 一直以为是从第一个杯子开始移动,然后再移动。还是题意没读懂,然后一直wa,一直找不出错点。实在没办法去codeforce上看了数据才知道。原来错在这了。 教训啊,题意一定要仔细看。
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn=1e6+60;bool vis[maxn];struct node{ int st,ed;}p[maxn];int main(void){ memset(vis,false,sizeof(vis)); int n,m,k; cin >> n>> m>> k; for(int i=1;i<=m;i++) { int t; scanf("%d",&t); vis[t]=true; } ll ans=1; for(int i=1;i<=k;i++) { scanf("%d%d",&p[i].st,&p[i].ed); } if(vis[1]==true) { printf("1\n"); return 0; } for(int i=1;i<=k;i++) { int st=p[i].st,ed=p[i].ed; if(st==ans)// 如果骨头ans在st。 { if(vis[ed]==true) { printf("%d\n",ed); return 0; } else ans=ed; } else if(ed==ans)//如果骨头ans在ed { if(vis[st]==true) { printf("%d\n",st); return 0; } else ans=st; } } cout << ans << endl;}
阅读全文
0 0
- 796B
- b
- b
- b
- //b
- B
- b
- B
- B
- B
- B
- b
- B
- B
- B
- B
- B
- B
- swiper入门小练习-移动端实现上下滑动翻整个页面(一)
- WPF中添加一个文本输入框,按Enter回车,执行绑定的Command
- C# 装箱、拆箱、泛型
- 阿哈磊的挑战11--16
- Mybatis 参数无法获取Parameter not found
- 796B
- Linux下用户组、文件权限详解
- 头条号如何提升互动度
- session和cookie作用原理,区别
- sklearn.metrics.precision_score 中 unknow is not supported 问题
- 01背包问题
- Powershell 编写和运行脚本
- swt浏览文件 显示文件目录 swt显示图片以及图片缩放处理
- Vivado IP核生成设置