A - Determinant

签到。

B - Quizzes

签到。

C - Super Ryuma

贪心,同时分情况讨论:

1.本身就在范围里面,就1次(特判起始点和终点重合)。

2.在两步范围内(\(|a-c|+|b-d|<=6\)),2次。

3.利用斜线,如果当前不能直接斜线过去,但是通过移动到范围里的点再过去,就2次。

4.在终点做一条和我两条对角线平行的线,交任意一条对角线上于一点,我就可以先移动到这个点再滑过去,2次。此时要看对角线(坐标和)奇偶性。交不到点就要3次。

详见代码。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; int main()
{
ll a = read(), b = read(), c = read(), d = read();
if(a==c&&b==d)
{
cout<<0<<endl;
}
else if(a+b==c+d||a-b==c-d||abs(a-c)+abs(b-d)<=3)
{
cout<<1<<endl;
}
else
{
if(abs(a-c)+abs(b-d)<=6) cout<<2<<endl; // 两步方框距离
else
{
int flag = 0;
for(int i=a-3; i<= a+3; i++) for(int j=b-3; j<=b+3; j++) //找方框里面能否有直接斜线到终点的
{
if(abs(i-a)+abs(j-b) <= 3&&i+j==c+d||i-j==c-d) flag = 1;
}
if(flag) cout<<2<<endl; //有就万幸
else //无的话
{ if(((a+b)&1LL)==((c+d)&1LL)) cout<<2<<endl; //看对角线奇偶性
else cout<<3<<endl;
}
}
} return 0;
}

D - increment of coins

题意:一开始有三种颜色的石子分别为A,B,C个。一次可以随机拿出一个石子,放回两个同颜色的。问把全部都替换成100个同色的需要的步数的期望。

思路:当前一个状态,如(97,98,99),往下有三个子状态:

1.(98,98,99)

2.(97,99,99)

3.(97,98,100)

同理这三个子状态往下也有三个状态,直到有一位到100。那么根据期望的定义,我们就知道当前的期望是三种可能需要的步数乘上对应概率,然后加和。

而这三种可能(子状态)所需要的步数又是他们各自的期望,这就分解了子问题,用DP求解即可。这里采用记忆化搜索。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; double dp[105][105][105]; double DP(int A, int B , int C)
{
if(A>=100||B>=100||C>=100) return 0;
if(dp[A][B][C] != -1) return dp[A][B][C]; dp[A][B][C] = ((DP(A+1,B,C)+1)*A/(double)(A+B+C))+((DP(A,B+1,C)+1)*B/(double)(A+B+C))+((DP(A,B,C+1)+1)*C/(double)(A+B+C));
return dp[A][B][C];
} int main()
{
rep(i,0,101) rep(j,0,101) rep(k,0,101) dp[i][j][k] = -1 ;
double a, b, c;
cin>>a>>b>>c;
printf("%.6lf\n",DP(a,b,c));
return 0;
}

E - Third Avenue

经典BFS问题,在走迷宫的问题上加了传送而已。我们先用map记录每个字母有哪些传送口,然后第一次遇到这个字母的时候,不但可以四方向走,而且还可以将传送位置丢进队列。有一点要注意的是,我第一次遇到这个字母的时候把能走的相同字母都传送过去,下次再遇到这个字母就没必要再看传送了,因为肯定不是最优(走老路),这样就将时间复杂度也降下来了O(26nm)。具体实现见代码。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include <string.h>
#include <stdio.h>
#include <unordered_map>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline int read(){ int f = 1; int x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; char s[3000][3000];
int n, m;
int vis[3000][3000];
int d[3000][3000];
int path[30];
unordered_map<int, vector<PII> > to; int Sx,Sy, Gx,Gy; bool check(int x, int y)
{
if(x>n||x<1||y>m||y<1||vis[x][y]||s[x][y]=='#') return false;
return true;
} ll bfs()
{
queue<PII> q;
d[Sx][Sy] = 0;
vis[Sx][Sy] = 1;
q.push(mp(Sx,Sy));
while(!q.empty())
{
int x = q.front().fi;
int y = q.front().se;
q.pop();
if(s[x][y] == 'G') return d[x][y];
rep(i,0,3)
{
int xx = x + dir[i][0];
int yy = y + dir[i][1];
if(check(xx,yy)&&!vis[xx][yy])
{
vis[xx][yy] = 1;
d[xx][yy] = d[x][y] + 1;
q.push(mp(xx,yy));
}
} if(s[x][y]>='a'&&s[x][y]<='z'&&!path[s[x][y]-'a'])
{
path[s[x][y]-'a'] = 1;
for(int i=0; i<to[s[x][y]-'a'].size(); i++)
{
int tox = to[s[x][y]-'a'][i].fi;
int toy = to[s[x][y]-'a'][i].se; if(check(tox,toy)&&!vis[tox][toy]&&!(tox==x&&toy==y))
{
vis[tox][toy] = 1;
d[tox][toy] = d[x][y] + 1;
q.push(mp(tox,toy));
}
}
}
}
return -1;
} int main()
{
cin>>n>>m;
char ch = getchar();
rep(i,1,n) scanf("%s",s[i]+1); rep(i,1,n) rep(j,1,m)
{
if(s[i][j] == 'S') Sx = i, Sy = j;
else if(s[i][j]=='G') Gx = i, Gy = j;
else if(s[i][j]>='a'&&s[i][j]<='z')
to[s[i][j]-'a'].pb(mp(i,j));
}
ll ans = bfs();
cout<<ans<<endl;
return 0;
}

AtCoder Beginner Contest 184 ABCDE 题解的更多相关文章

  1. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  2. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  3. AtCoder Beginner Contest 089完整题解

    A - Grouping 2 Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement There a ...

  4. AtCoder Beginner Contest 184 F - Programming Contest (双向搜索)

    题意:有一个长度为\(n\)的数组,你可以从中选一些数出来使得它们的和不大于\(t\),问能选出来的最大的和是多少. 题解:\(n\)的数据范围是\(40\),直接二进制枚举贴TLE,之前写过这样的一 ...

  5. AtCoder Beginner Contest 184 E - Third Avenue (BFS)

    题意:给你一张图,\(S\)表示起点,\(G\)表示终点,\(.\)表示可以走,#表示不能走,小写字母可以传送到任意一个相同的字母的位置,问从\(S\)走到\(G\)的最小步数. 题解:假如不考虑字母 ...

  6. 2018.09.08 AtCoder Beginner Contest 109简要题解

    比赛传送门 水题大赛? 全是水题啊!!! T1 ABC333 就是判断是不是两个数都是奇数就行了. 代码: #include<bits/stdc++.h> using namespace ...

  7. Atcoder Beginner Contest 138 简要题解

    D - Ki 题意:给一棵有根树,节点1为根,有$Q$次操作,每次操作将一个节点及其子树的所有节点的权值加上一个值,问最后每个节点的权值. 思路:dfs序再差分一下就行了. #include < ...

  8. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  9. AtCoder Beginner Contest 153 题解

    目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...

  10. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

随机推荐

  1. ShardingSphere 解决关联表查询问题的详细方案

    一.基础概念 在分库分表场景下,关联表(JOIN)查询的复杂性主要源于数据分布在不同的数据库或表中.ShardingSphere 通过 绑定表(Binding Table) 和 广播表(Broadca ...

  2. 重生之我是操作系统(十)----I/O管理

    简介 操作系统的I/O管理(input/output mannagment)是协调,控制计算机与外部设备(如磁盘,键盘,网络接口)等之间数据交换的核心功能.实现可靠高效且统一(隐藏设备差异,如磁盘.串 ...

  3. CTF实验吧:登陆一下? 不一样的SQL注入

    http://ctf5.shiyanbar.com/web/wonderkun/web/index.html 发现 过滤了很多SQL敏感字符,并且 转码绕过也并不行 发现'和=没有进行过滤 考虑万能密 ...

  4. Vue相关笔记

    Promise基本使用 Promise是异步编程的一种解决方案,用于一个异步操作的最终完成(或失败)及其结果值的表示,比传统的回调函数方案更加合理. var promise = new Promise ...

  5. 【记录】Excel 2021|(三)VBA使用Selenium自动登录网页

    文章目录 1 安装 Selenium Basic 2 下载webdriver 3 自动登录 1 安装 Selenium Basic 首先需要安装Selenium Basic,才能在工具栏中找到Sele ...

  6. 卢卡斯(lucas)定理

    对于质数 \(p\),有 \[{\Large \begin{aligned} & \binom{n}{m} \equiv \binom{\left \lfloor n/p \right \rf ...

  7. Possible data inputs to DataFrame constructor

    Possible data inputs to DataFrame constructor: import pandas as pd import numpy as np (1) 2D ndarray ...

  8. Win32汇编学习笔记05

    定位关键点3种方法: 过程函数 api 字符串 但是不确定用要哪一种方法,可以3种方法都用一下,因为在不同的程序,实用的方法是不一样的 窗口程序看控件信息 1.通过OD去看 还可以用 spy ++ 查 ...

  9. 卡掉hash的方法

    大质数hash 通常,这个质数会选择在 \(10^9\) 附近,如 \(998244353\),\(10^9+7\). 考虑生日碰撞,欲达到 50% 成功率,需要尝试的次数为 \[\begin{ali ...

  10. Strands Agents(一)Strands Agents 介绍

    Strands Agent AWS 最新开源的 Strands Agents SDK 是一款采用模型驱动架构的 AI 代理开发框架,旨在通过极简开发方式,帮助开发者快速构建和部署 AI 代理.它将代理 ...