Codeforces Round #408 (Div. 2)-B. Find The Bone
来源:互联网 发布:电脑必备软件2016 编辑:程序博客网 时间:2024/06/07 09:07
输入n,m,k
给定你一排水杯,给你m,第一个位置有一个骨头。,说明有m个位置有洞,有洞的在反转的时候无法被移动,而没有洞的在反转杯子的时候会在杯子里。(速度很快),问你最后骨头的位置。
我开始题都没读懂,以为是遍历数据,发现一个有洞了就掉进去了并且标记一下。。样例第一组都是1,所以没有怎么看题。。真吭。
首先要明确如果一有洞那么 结果肯定是1,
后来睡醒了改啊改改了一种写法,又看了别人的博客,这两种我感觉我的比较省内存。。。
#include <bits/stdc++.h>using namespace std;int main(){ int n,m,l; map<int,int>Map; int a,b; scanf("%d%d%d",&n,&m,&l); for(int i=1;i<=m;i++) { scanf("%d",&a); Map[a]=1; } int ans=0; int flag=0; bool gx=false; int wz=1; for(int i=1;i<=l;i++) { scanf("%d%d",&a,&b); if(a==wz)//如果位置在a,说明a肯定不是坑,这一段都简化了,以前写的都要判断a和b,后来发现没意义。 { if(Map[b]&&!flag) { ans=b; flag=1; gx=true; } wz=b; } else if(b==wz) {if(Map[a]&&!flag) {ans=a;flag=1; gx=true; } wz=a; } } if(Map[1]) {cout<<"1"<<endl; } else if(flag) printf("%d\n",ans); else printf("%d\n",wz); //把结果分为中途掉和 完成时看错题的结果。。改了改能过。。 ans就是掉的洞的地方,而wz是最后一路没有掉的结束 return 0;}
#include <iostream>//参考别人的博客的写法。#include <cstdio>#include <algorithm>#include <vector>#include <cstring>#include <queue>#include <cmath>#include <map>using namespace std;const int maxn = 1e6+100;const int inf = 0x7ffffff;const int mod = 1e9;int vis[maxn];int main(void){ int n,m,k; int u,v,a; scanf("%d%d%d",&n,&m,&k); memset(vis,0,sizeof(vis)); for(int i=1;i<=m;i++) { scanf("%d",&a); vis[a]=-1; } if(vis[1]!=-1) vis[1]=1;//通过一个1模拟状态。 int ans=1; for(int i=1;i<=k;i++) { scanf("%d%d",&u,&v); if(ans==u&&vis[u]!=-1) { if(vis[v]!=-1) swap(vis[u],vis[v]); ans=v; } else if(ans==v&&vis[v]!=-1) { if(vis[u]!=-1) swap(vis[u],vis[v]); ans=u; } } printf("%d\n",ans); return 0;}
1 0
- codeforces round#408(div.2) B. Find The Bone
- Codeforces Round #408 (Div. 2)-B. Find The Bone
- Codeforces Round #408 (Div. 2) B. Find The Bone
- Codeforces Round #408 (Div. 2) B.Find The Bone(模拟)
- Codeforces Round #408 B. Find The Bone
- Codeforces Round #408 (Div. 2) B. Find The Bone【模拟】水题~
- CodeForces 796B Find The Bone
- 【CodeForces 796B】Find The Bone
- 【Codeforces 796 B. Find The Bone】
- Find The Bone (Codeforces-796B)
- 【Codeforces Round #398 (Div. 2)】Codeforces 767B The Queue
- B. The Festive Evening(Codeforces Round #426 (Div. 2) B)
- B. Find The Bone
- Codeforces Round #258 (Div. 2) 2B Sort the Array
- Codeforces Round #202 (Div. 2) B.Color the Fence
- Codeforces Round #202 (Div. 2) B. Color the Fence
- Codeforces Round #258 (Div. 2/B)/Codeforces451B_Sort the Array
- Codeforces Round #258 (Div. 2) B. Sort the Array
- 程序-进程-线程
- sql,hql,jpql(ejb)介绍
- Java容器总结
- 将oracle的sql文件转换成mysql的sql文件
- 高性能全局事务服务GTS
- Codeforces Round #408 (Div. 2)-B. Find The Bone
- poj 3686 The Windy's (KM算法)
- Github全面详解-02注册Github
- poj 3565 Ants (KM算法)
- 矩形嵌套
- Full GC为什么那么慢?为什么老年代垃圾回收效率比新生代低很多?为什么Minor gc速度比Major GC慢?
- ROS学习(基于Ubuntu 15.04 和ROS Jade)第三章 ROS核心教程 之 4 构建一个包
- 2017 Wuhan University Programming Contest (Online Round) E. Lost in WHU(矩阵快速幂)
- 模板库